cd C:\fop
java -cp build\fop.jar;lib\avalon-framework-4.2.0.jar;lib\commons-logging-1.0.4.jar;lib\commons-io-1.3.1.jar org.apache.fop.fonts.apps.TTFReader -ttcname "MS Mincho" C:\WINDOWS\Fonts\msmincho.ttc MsMincho.xml
java -cp build\fop.jar;lib\avalon-framework-4.2.0.jar;lib\commons-logging-1.0.4.jar;lib\commons-io-1.3.1.jar org.apache.fop.fonts.apps.TTFReader -ttcname "MS Gothic" c:\windows\fonts\msgothic.ttc MsGothic.xml
java -cp build\fop.jar;lib\avalon-framework-4.2.0.jar;lib\commons-logging-1.0.4.jar;lib\commons-io-1.3.1.jar org.apache.fop.fonts.apps.TTFReader -fn "IPAMincho" C:\WINDOWS\Fonts\ipam.ttf IPAMincho.xml
java -cp build\fop.jar;lib\avalon-framework-4.2.0.jar;lib\commons-logging-1.0.4.jar;lib\commons-io-1.3.1.jar org.apache.fop.fonts.apps.TTFReader -fn "IPAGothic" C:\WINDOWS\Fonts\ipag.ttf IPAGothic.xml
cfg.xml
<?xml version="1.0"?> <fop version="1.0"> <renderers> <renderer mime="application/pdf"> <fonts> <font metrics-url="file:///C:/fop/conf/MsMincho.xml" kerning="yes" embed-url="file:///C:/WINDOWS/Fonts/msmincho.ttc"> <font-triplet name="MS Mincho" style="normal" weight="normal"/> <font-triplet name="MS Mincho" style="normal" weight="bold"/> <font-triplet name="MS Mincho" style="italic" weight="normal"/> <font-triplet name="MS Mincho" style="italic" weight="bold"/> </font> <font metrics-url="file:///C:/fop/conf/MsGothic.xml" kerning="yes" embed-url="file:///C:/WINDOWS/Fonts/msgothic.ttc"> <font-triplet name="MS Gothic" style="normal" weight="normal"/> <font-triplet name="MS Gothic" style="normal" weight="bold"/> <font-triplet name="MS Gothic" style="italic" weight="normal"/> <font-triplet name="MS Gothic" style="italic" weight="bold"/> </font> <font metrics-url="file:///C:/fop/conf/IPAMincho.xml" kerning="yes" embed-url="file:///C:/WINDOWS/Fonts/ipam.ttf"> <font-triplet name="IPAMincho" style="normal" weight="normal"/> <font-triplet name="IPAMincho" style="normal" weight="bold"/> <font-triplet name="IPAMincho" style="italic" weight="normal"/> <font-triplet name="IPAMincho" style="italic" weight="bold"/> </font> <font metrics-url="file:///C:/fop/conf/IPAGothic.xml" kerning="yes" embed-url="file:///C:/WINDOWS/Fonts/ipag.ttf"> <font-triplet name="IPAGothic" style="normal" weight="normal"/> <font-triplet name="IPAGothic" style="normal" weight="bold"/> <font-triplet name="IPAGothic" style="italic" weight="normal"/> <font-triplet name="IPAGothic" style="italic" weight="bold"/> </font> </fonts> </renderer> </renderers> </fop>
fop.batの最後の方にある行のorg.apache.fop.cli.Mainの後に-c C:\fop\conf\cfg.xmlを追加する。
fop.bat
"%JAVACMD%" %JAVAOPTS% %LOGCHOICE% %LOGLEVEL% -cp "%LOCALCLASSPATH%" org.apache.fop.cli.Main -c C:\fop\conf\cfg.xml %FOP_CMD_LINE_ARGS%
hello.fo
<?xml version="1.0" encoding="UTF-8"?> <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> <fo:layout-master-set> <fo:simple-page-master master-name="simple"> <fo:region-body margin-top="1cm"/> <fo:region-before extent="1cm"/> <fo:region-after extent="1cm"/> </fo:simple-page-master> </fo:layout-master-set> <fo:page-sequence master-reference="simple"> <fo:flow flow-name="xsl-region-body"> <fo:block font-family="MS Gothic" font-style="normal" font-size="72pt" text-align="center"> こんにちはこんにちは! </fo:block> </fo:flow> </fo:page-sequence> </fo:root>
fop hello.fo hello.pdf
もしくは
fop -fo hello.fo -pdf hello.pdf
Docook(XML)とXSLからPDFを生成するには以下の通り。
fop -xml test.xml -xsl docbook.xsl -pdf test.pdf
Pandocと組み合わせてMarkdownからPDFを生成するには以下の通り。
pandoc --strict -f markdown -t docbook test.txt > test.xml | fop -xml test.xml -xsl docbook.xsl -pdf test.pdf
docbook.xsl
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:import href="C:\fop\docbookxsl\fo\docbook.xsl"/> <xsl:param name="paper.type">A4</xsl:param> <xsl:param name="title.font.family">MS Gothic</xsl:param> <xsl:param name="body.font.family">MS Gothic</xsl:param> <xsl:param name="monospace.font.family">MS Gothic</xsl:param> </xsl:stylesheet>
インポートしているdocbook-xslはhttp://sourceforge.net/project/showfiles.php?group_id=21935&package_id=16608 から入手する。
Windowsの場合はバイナリ、Ubuntuの場合はHardyならパッケージ、Gustyとそれより前の場合は
sudo apt-get install ghc6 libghc6-xhtml-dev libghc6-mtl-dev libghc6-network-dev
wget http://pandoc.googlecode.com/files/pandoc-0.46.tar.gz
tar xvzf pandoc-0.46.tar.gz
cd pandoc-0.46
make
sudo make install
MarkdownからDocBookに変換するには
pandoc -f markdown -t docbook sample.txt -o sample.xml
HTML、XMLタグを削除されないようにする場合には「-R」オプションを追加する。 オリジナルのMarkdownの部分のみを処理する場合は「--strict」オプションを追加する。
処理するテキストの前後にテンプレートを追加する場合は
pandoc -B before.txt -A after.txt -f markdown -t latex hello.txt -o test.tex
内部処理はUTF-8で行われるのでiconvなどであらかじめエンコードを変換する必要がある。
iconv -f EUCJP -t UTF-8 eucjp_sample.txt > utf8_sample.txt
例えばEUC-JPのmarkdownのテキストをdocbookに変換してコマンドプロンプト上に表示させるにはパイプを使う。
iconv -f EUCJP -t utf-8 markdown_sample.txt | pandoc -t docbook | iconv -f UTF-8 -t CP932
Ubuntuで行う場合。Windowsの場合日本語表示が問題になる。
ソースの入手
docbook-xslの設定
http://sourceforge.net/project/showfiles.php?group_id=21935 から入手する。
cd src/tools
tar zxvf docbook-xsl-X.YY.Z.tar.gz
mv docbook-xsl-X.YY.Z xsl
ツールのインストール
sudo apt-get install subversion libxslt1.1 libxml2-dev libxml2-utils xsltproc
HTMLのビルド
cd en
make all-html
PDFのビルド
export JAVA_HOME=/usr/lib/jvm/java-6-sun
export PATH=$PATH:$JAVA_HOME/bin
export FOP_OPTS="-Xms100m -Xmx200m"
のコマンドを実行した後で
cd en
make all-pdf
トップページに戻る