Skip to content

Instantly share code, notes, and snippets.

@masakielastic
Created February 19, 2009 07:33
Show Gist options
  • Save masakielastic/66775 to your computer and use it in GitHub Desktop.
Save masakielastic/66775 to your computer and use it in GitHub Desktop.
How to generate HTML and pdf from DocBook in Japanese

How to generate pdf from DocBook in Japanense

OS

Ubuntu 8.10

install Sun Java

sudo apt-get install sun-java6-jdk
sudo update-java-alternatives -s java-6-sun

check Java version:

java -version

result:

java version "1.6.0_10"
Java(TM) SE Runtime Environment (build 1.6.0_10-b33)
Java HotSpot(TM) Client VM (build 11.0-b15, mixed mode, sharing)

install build tools

sudo apt-get install fop xsltproc

install docbook stylesheets

sudo apt-get install docbook docbook-xsl docbook-dsssl

generate html with xsltproc

xsltproc -o output.html --stringparam html.stylesheet main.css /usr/share/xml/docbook/stylesheet/nwalsh/xhtml/docbook.xsl input.xml

generate pdf with Apache FOP

fop -xsl /usr/share/xml/docbook/stylesheet/nwalsh/fo/docbook.xsl -xml input.xml -pdf output.pdf

If you want to another language except Englich, you need to set fonts configuration.

fop -c config.xml -xsl config.xsl -xml input.xml -pdf output.pdf

generate fonts metrics files(config.xml)

For example, you want to use VL Gothic(Japanese):

fop-ttfreader /usr/share/fonts/truetype/vlgothic/VL-PGothic-Regular.ttf VL-PGothic-Regular.xml

VL Gothic is installed by

sudo apt-get install ttf-vlgothic

See Also

DocBook - Community Ubuntu Documentation

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:import href="/usr/share/xml/docbook/stylesheet/nwalsh/fo/docbook.xsl"/>
<xsl:param name="paper.type">A4</xsl:param>
<xsl:param name="title.font.family">VLPGothic</xsl:param>
<xsl:param name="body.font.family">VLPGothic</xsl:param>
<xsl:param name="monospace.font.family">VLPGothic</xsl:param>
</xsl:stylesheet>
<?xml version="1.0" ?>
<fop version="1.0">
<renderers>
<renderer mime="application/pdf">
<fonts>
<font
metrics-url="/path/to/VL-PGothic-Regular.xml"
kerning="yes"
embed-url="/usr/share/fonts/truetype/vlgothic/VL-PGothic-Regular.ttf" >
<font-triplet name="VLPGothic" style="normal" weight="100"/>
<font-triplet name="VLPGothic" style="normal" weight="200"/>
<font-triplet name="VLPGothic" style="normal" weight="300"/>
<font-triplet name="VLPGothic" style="normal" weight="400"/>
<font-triplet name="VLPGothic" style="normal" weight="500"/>
<font-triplet name="VLPGothic" style="normal" weight="600"/>
<font-triplet name="VLPGothic" style="normal" weight="700"/>
<font-triplet name="VLPGothic" style="normal" weight="800"/>
<font-triplet name="VLPGothic" style="normal" weight="900"/>
</font>
</fonts>
</renderer>
</renderers>
</fop>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://docbook.org/xml/4.5/docbookx.dtd">
<article>
<title>Title</title>
<sect1>
<title>Heading</title>
<para>Content</para>
</sect1>
</article>
<?php
$xml = new DOMDocument();
$xml->load('test.xml');
$xsl = new DOMDocument();
$xsl->load('/usr/share/xml/docbook/stylesheet/nwalsh/xhtml/docbook.xsl');
$xslt = new XSLTProcessor();
$xslt->importStylesheet($xsl);
$html = $xslt->transformToXML($xml);
$config = array(
'indent' => true,
'output-xhtml' => true,
'wrap' => 200
);
$tidy = new tidy;
$tidy->parseString($html, $config, 'utf8');
$tidy->cleanRepair();
echo $tidy;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment