Engineer in Tokyo

Django勉強会Disc.8の資料をRSTにした

id:tokibito見つけてくれたrst2pdfを使ってid:tmatsuoとDjango勉強会Disc.8 ハンズオンC の資料をPDFにした。

ほとんどid:tokibitoと同じやり方でPDFを吐き出したけど、問題点が二つあった。

rst2pdfをたたくとja.jsonを指定する上、--font-folderも指定しないと日本語が化ける。Ubuntuの場合VL-Gothicで充分なので、

rst2pdf \
    -s ja.json,perldoc.json \
    --font-folder="/usr/share/fonts/truetype/vlgothic" \
    django-hack-a-thon-get-handson.part2.rst

問題点の二つ目は、rst2pdfwordWrapが段落に対して、一つのフラグメント(?)しか扱えないようで、エラーが出た。

[ERROR] styles.py L191 Error processing font VL-Gothic-Regular: Can't open file "ipam.otf"
[ERROR] styles.py L192 Registering VL-Gothic-Regular as Helvetica alias
Traceback (most recent call last):
  File "/usr/bin/rst2pdf", line 8, in <module>
    load_entry_point('rst2pdf==0.9', 'console_scripts', 'rst2pdf')()
  File "/usr/lib/python2.5/site-packages/rst2pdf-0.9-py2.5.egg/rst2pdf/createpdf.py", line 1212, in main
    compressed=options.compressed)
  File "/usr/lib/python2.5/site-packages/rst2pdf-0.9-py2.5.egg/rst2pdf/createpdf.py", line 991, in createPdf
    pdfdoc.build(elements)
  File "/usr/lib/python2.5/site-packages/Reportlab-2.1-py2.5.egg/reportlab/platypus/doctemplate.py", line 740, in build
    self.handle_flowable(flowables)
  File "/usr/lib/python2.5/site-packages/Reportlab-2.1-py2.5.egg/reportlab/platypus/doctemplate.py", line 638, in handle_flowable
    if frame.add(f, self.canv, trySplit=self.allowSplitting):
  File "/usr/lib/python2.5/site-packages/Reportlab-2.1-py2.5.egg/reportlab/platypus/frames.py", line 141, in _add
    w, h = flowable.wrap(aW, h)
  File "/usr/lib/python2.5/site-packages/Reportlab-2.1-py2.5.egg/reportlab/platypus/paragraph.py", line 567, in wrap
    self.blPara = self.breakLinesCJK([first_line_width, later_widths])
  File "/usr/lib/python2.5/site-packages/Reportlab-2.1-py2.5.egg/reportlab/platypus/paragraph.py", line 819, in breakLinesCJK
    raise ValueError('CJK Wordwrap can only handle one fragment per paragraph for now')
ValueError: CJK Wordwrap can only handle one fragment per paragraph for now

なので、面倒くさいから、wordWrapを無効にした。

{
    "embeddedFonts": [
        [
            "VL-Gothic-Regular.ttf",
            "VL-PGothic-Regular.ttf",
            "ipam.otf",
            "verdanaz.ttf"
        ]
    ],
    "fontsAlias": {
        "stdFont": "VL-PGothic-Regular",
        "stdBold": "VL-PGothic-Regular",
        "stdItalic": "VL-PGothic-Regular",
        "stdMono": "VL-Gothic-Regular"
    },
    "styles": [
        [
            "base",
            {
                "wordWrap": "<strong>None</strong>"
            }
        ],
        [
            "literal",
            {
                "wordWrap": "None"
            }
        ]
    ]
}

Bitbucketに保存してる。