Ian Lewis
Ian Lewis is a web developer living in Tokyo Japan. His current interests are in Django, python, alternative databases and rapid web application development. About Me...
  • Django勉強会Disc.8の資料をRSTにした

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

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

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

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

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

    [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 
        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": "None"
        }],
        ["literal" , {
          "wordWrap": "None"
        }]
      ]
    }
    

    bitbucketに保存してる。

    PDF

    Send feedback このエントリーを含むはてなブックマーク はてなブックマーク - Django勉強会Disc.8の資料をRSTにした