LoginSignup
1
1

More than 5 years have passed since last update.

(メモ)rst2pdfでreStructuredTextをPDFに変換する

Last updated at Posted at 2016-12-16

背景

  • reSTで書いたドキュメントをPDFで出力したい
    • 日本語にも対応させたい

動作環境

rst2pdf on Amazon Linuxでやってみます

rst2pdf

必要なパッケージのインストール

コマンド
sudo yum install libjpeg-devel zlib-devel gcc

rst2pdfのインストール

コマンド
sudo easy_install rst2pdf

フォントのインストール

2016/12/16時点の最新版を利用します。

VLゴシックフォント

コマンド
wget http://jaist.dl.sourceforge.jp/vlgothic/62375/VLGothic-20141206.zip
unzip VLGothic-20141206.zip
cd VLGothic
sudo cp *.ttf /usr/share/fonts/
fc-cache
cd ~

フォントの設定

コマンド
cat << EOF > ja.json
{
    "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"
        }]
    ]
}
EOF

JSONファイルの検証をしましょう。

コマンド
jsonlint -q ja.json

jsonlintのインストールは以下の手順で

コマンド
sudo yum install npm --enablerepo=epel -y
sudo npm install -g jsonlint

reSTファイルの生成

こちらのブログより拝借しました&全体的に参考にさせて頂きました。

(8日目) Sphinx から PDF を生成してみよう (rst2pdf 編)

コマンド
cat << EOF > index.rst
=============================
rst2pdf sample documentation
=============================

これは rst2pdf を利用するサンプルです。

blockdiag の紹介
=================

blockdiag シリーズは以下のパッケージから構成されています。

* blockdiag
* seqdiag
* actdiag
* nwdiag
   * nwdiag
   * rackdiag

blockdiag パッケージとコマンド群
=================================

もちろん表も書けます。

============  =========
パッケージ名  コマンド
============  =========
blockdiag     blockdiag
seqdiag       seqdiag
actdag        actdiag
nwdiag        nwdiag
              rackdiag
============  =========

EOF

PDFファイルの生成

コマンド
rst2pdf -s ja index.rst

所感

  • インストールは簡単
  • デザインに制約(がありそう?)

以上

1
1
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
1
1