LoginSignup
28
26

More than 5 years have passed since last update.

Windows 上で asciidoctor を使って日本語を含む asciidoc から pdf を作成する方法 (2015年5月)

Last updated at Posted at 2015-05-04

まとめ

現時点 (2015年5月) でおそらく一番簡単な Windows 上で asciidoctor を使って日本語を含む asciidoc から pdf を作成する手順。

環境

  • Windows 7 64 bit
  • ActiveScriptRuby (Ruby 2.2)
  • asciidoctor (1.5.2)
  • asciidoctor-pdf (1.5.0.alpha.6)
  • and their dependencies

手順

  1. ActiveScriptRuby の最新版を C:\Ruby22 にインストール
  2. Ruby-2.2 console から gem install asciidoctor
  3. gem install --pre asciidoctor-pdf
  4. C:\Ruby22\lib\ruby\gems\2.2.0\gems\asciidoctor-pdf-1.5.0.alpha.6\data\themes にある default-theme.yml を編集しておく(下記)
  5. C:\Ruby22\lib\ruby\gems\2.2.0\gems\prawn-1.2.1\lib\prawn\text\formatted にある line_wrap.rb を編集しておく(下記)。詳細は Add a CJK theme #82 を参照のこと
  6. 以下の example.adoc について asciidoctor-pdf example.adoc
example.adoc
= こんにちは、AsciiDoc!
Doc Writer <doc@example.com>

http://asciidoc.org[AsciiDoc] 入門。

AsciiDoc は、意味的には DocBook XML のに相当するが、プレーン·テキスト·マークアップの規則を使用して、人間が読めるドキュメントフォーマット、である。 AsciiDoc は文書は、任意のテキストエディタを使用して作成され、「そのまま"または、HTML や DocBook のツールチェーンでサポートされている他のフォーマット、すなわち PDF、TeX の、Unix の man ページ、電子書籍、スライドプレゼンテーションなどにレンダリングすることができます。

== 第一節

* アイテム 1
* アイテム 2

[source,ruby]
puts "Hello, World!"

結果

example.pdf.png

手順 4 を行わないと、以下のようになる、はず。

example_fail.pdf.png

default-theme.yml の編集

default-theme.yml
--- default-theme.yml.old
+++ default-theme.yml
@@ -16,8 +16,11 @@
       bold: mplus1mn-bold-ascii.ttf
       italic: mplus1mn-italic-ascii.ttf
       bold_italic: mplus1mn-bolditalic-ascii.ttf
-    #Mplus1pMultilingual:
-    #  normal: mplus1p-regular-multilingual.ttf
+    Mplus1pMultilingual:
+      normal: mplus1p-regular-multilingual.ttf
+      bold: mplus1p-regular-multilingual.ttf
+      italic: mplus1p-regular-multilingual.ttf
+      bold_italic: mplus1p-regular-multilingual.ttf
     #FontAwesome:
     #  normal: fontawesome-regular.ttf
   # FIXME using fallbacks breaks use of custom font styles (fixed in Prawn 1.2.1!)
@@ -33,7 +36,7 @@
   size: Letter
 base:
   font_color: 333333
-  font_family: NotoSerif
+  font_family: Mplus1pMultilingual
   # choose one of these font_size/line_height_length combinations
   #font_size: 14
   #line_height_length: 20

当然、斜体等は無視される

prawn の line_wrap.rb の編集

line_wrap.rb
$ diff -u line_wrap.rb.old  line_wrap.rb
@@ -118,7 +118,8 @@
         # The pattern used to determine chunks of text to place on a given line

         #
         def scan_pattern
-          pattern = "[^#{break_chars}]+#{soft_hyphen}|" +
+          pattern = "\\p{Han}|\\p{Hiragana}|\\p{Katakana}|\\p{Common}|" + # <-break all CJ chars
+            "[^#{break_chars}]+#{soft_hyphen}|" +
             "[^#{break_chars}]+#{hyphen}+|" +
             "[^#{break_chars}]+|" +
             "[#{whitespace}]+|" +

問題点

  • Doc Writer <doc@example.com> がうまく処理されない
  • 英語と日本語の間隔が十分はうまく処理されない(ことがある)
  • 以下の Warning が出る
stdout
C:/Ruby22/lib/ruby/gems/2.2.0/gems/pdf-core-0.2.5/lib/pdf/core/pdf_object.rb:55:
 warning: regexp match /.../n against to UTF-8 string
C:/Ruby22/lib/ruby/gems/2.2.0/gems/pdf-core-0.2.5/lib/pdf/core/pdf_object.rb:55:
 warning: regexp match /.../n against to UTF-8 string
28
26
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
28
26