6
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Sphinxについてのメモ その2(rst2pdf拡張を使ったPDF出力)

6
Last updated at Posted at 2014-09-27

rst2pdfを使って、作成したドキュメントをpdfで出力する方法

環境

OS:Mac OS X 10.9.5
Python:Ver.2.7.7

rst2pdfのインストール

$ sudo easy_install rst2pdf
・・・
Finished processing dependencies for rst2pdf

この結果が出れば完了。

設定ファイルの編集

conf.py

conf.pyに以下を追加

extensions = ['rst2pdf.pdfbuilder']
# -- Options for PDF output --------------------------------------------------
pdf_documents = [
    ('index', u'MyProject', u'My Project', u'Author Name'),
]
pdf_stylesheets = ['sphinx','kerning','a4','ja']
pdf_language = "ja"

Makefile

Makefileに以下を追加

pdf:
	$(SPHINXBUILD) -b pdf $(ALLSPHINXOPTS) $(BUILDDIR)/pdf
	@echo
	@echo "Build finished. The PDF files are in _build/pdf."

ja.json

ja.jsonを追加する

{
    "embeddedFonts" : [
        "VL-Gothic-Regular.ttf",
        "VL-PGothic-Regular.ttf",
        "ipam.otf",
        "ipag.otf",
        "ipagp.otf",
        "ipamp.otf"
    ],
    "fontsAlias" : {
        "stdFont": "VL-PGothic-Regular",
        "stdBold": "VL-PGothic-Regular",
        "stdItalic": "VL-PGothic-Regular",
        "stdBoldItalic": "VL-PGothic-Regular",
        "stdMono": "VL-Gothic-Regular",
        "stdMonoBold": "VL-Gothic-Regular",
        "stdMonoItalic": "VL-Gothic-Regular",
        "stdMonoBoldItalic": "VL-Gothic-Regular",
        "stdSans": "VL-Gothic-Regular",
        "stdSansBold": "VL-Gothic-Regular",
        "stdSansItalic": "VL-Gothic-Regular",
        "stdSansBoldItalic": "VL-Gothic-Regular"
    },
    "styles" : [
        ["base" , {
            "wordWrap": "CJK"
        }],
        ["literal" , {
            "wordWrap": "None"
        }]
     ]
 }

ビルド

$ make pdf

_build/pdfフォルダ内に生成される。

エラーが出た場合

rst2pdfのインストール時に以下のようなエラーが出た場合

error: Setup script exited with error: command 'cc' failed with exit status 1

xcode-selectのインストールを行う

$ xcode-select --install
6
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?