Sphinx で PDF 作成 #sphinxjp
インストール
画像を入れたいので、Python Imaging Library (PIL) http://www.pythonware.com/products/pil/ もインストール。http://effbot.org/downloads/PIL-1.1.7.win32-py2.6.exe をダウンロードして実行。
rst2pdf - Project Hosting on Google Code http://code.google.com/p/rst2pdf/ から rst2pdf-0.16.tar.gz をダウンロードして python setuo.py install
http://code.google.com/p/rst2pdf/source/browse/trunk/doc/manual.txt を見ながら設定。
make.bat
make pdf 用のコードを追加。
conf.py
extensions に 'sphinx.ext.autodoc','rst2pdf.pdfbuilder' 追加。
# -- Options for PDF output -------------------------------------------------- 以下の貼り付け。
pdf_font_path = ['C:\WINDOWS\Fonts']
pdf_language = "ja"
pdf_stylesheets = ['sphinx','kerning','a4','ja'] にして、ja.json をプロジェクトのディレクトリへ作成。
ja.json
"wordWrap": "CJK" なんかも追加したかったけれど、ここにあるような*1エラーが出るのでフォントの指定だけ。
embeddedFontsで4つのフォントを指定しているけれど、それぞれがRegular, Bold, Italic, Bold Italicに相当するのかな? 4つ目のフォントにArial.ttfとか指定したらリンクになっている文字の日本語が化けた。単純に埋め込みたいフォントを列挙する訳じゃないのか? ここ *2 を見てみると単純に列挙しているだけみたいだけどな……。
ja.json
{
"embeddedFonts" : [
[
"VL-Gothic-Regular.ttf",
"VL-PGothic-Regular.ttf",
"ipam.ttf",
"ipam.ttf"
]
],
"fontsAlias" : {
"stdFont": "VL-PGothic-Regular",
"stdBold": "VL-PGothic-Regular",
"stdBoldItalic": "VL-PGothic-Regular",
"stdItalic": "VL-PGothic-Regular",
"stdMono": "VL-Gothic-Regular",
"stdMonoBold": "VL-Gothic-Regular",
"stdMonoBoldItalic": "VL-Gothic-Regular",
"stdMonoItalic": "VL-Gothic-Regular",
"stdSans": "VL-PGothic-Regular",
"stdSansBold": "VL-PGothic-Regular",
"stdSansBoldItalic": "VL-PGothic-Regular",
"stdSansItalic": "VL-PGothic-Regular"
}
}
参考
Sphinxを使ってPDFドキュメントを生成する - azuki note http://d.hatena.ne.jp/w650/20091120/1258703735
Sphinxを使ってPDFドキュメントを生成する(続き) - azuki note http://d.hatena.ne.jp/w650/20100216/1266287625
Sphinxで日本語PDFを生成する - 湘南ぱいそん http://d.hatena.ne.jp/MiCHiLU/20091009/1255065687
*1:Windows環境でSphinxを使って日本語PDFを作成するメモ - 記憶は削除の方向で http://d.hatena.ne.jp/re_guzy/20101012/p1
*2:rst2pdf拡張を使ったPDFファイル作成 http://sphinx-users.jp/cookbook/pdf/rst2pdf.html