9
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

日本語を含む OpenAPI ドキュメントをPDF出力したかった

Last updated at Posted at 2022-10-17

表記の件やった際の覚書。

PDFジェネレータ

  • RapiPdfを使用
      しばらく更新されてないけど、まぁそんな変わるもんでもないのでヨシ。

(2024-12-06追記)

RapiPdfが古いんで、nodeのバージョンアレする必要があります
とりあえず

  • Node 16.13.2 使用
npm install
npm run build
npm run serve

で動くのは確認。
(追記ここまで)

準備

# とりあえずインストールして
yarn install 
yarn build

# packageでpdfmakeが入るのでフォント追加の準備
cd ./node_modules/pdfmake
mkdir -p examples/fonts

# フォント定義ファイル(vfs_fonts.js)生成
node build-vfs.js "./examples/fonts"

# 移動
cd {RapiPdfのルート}

# 生成したフォント定義ファイルをコピー
cp ./node_modules/pdfmake/vfs_fonts.js ./src/

# ソースを少々変更
vi ./src/pdf-gen.js

# --- 差分 ---
L.41 -    mono: { font: 'RobotoMono', fontSize: 10 },
L.42 -    monoSub: { font: 'RobotoMono', fontSize: 8 },
L.41 +    mono: { font: 'IPAPGothic', fontSize: 10 },
L.42 +    monoSub: { font: 'IPAPGothic', fontSize: 8 },

L.96    pdfMake.fonts = {
-    Roboto: {
-      normal: 'Roboto-Regular.ttf',
-      bold: 'Roboto-Medium.ttf',
-      italics: 'Roboto-Italic.ttf',
-      bolditalics: 'Roboto-Medium.ttf',
-    },
-    RobotoMono: {
-      normal: 'RobotoMono-Regular.ttf',
-      bold: 'RobotoMono-Regular.ttf',
-      italics: 'RobotoMono-Regular.ttf',
-      bolditalics: 'RobotoMono-Regular.ttf',
+    IPAPGothic: {
+      normal: 'ipagp.ttf',
+      bold: 'ipagp.ttf',
+      italics: 'ipagp.ttf',
+      bolditalics: 'ipagp.ttf',
     },

L.111 -  // pdfMake.vfs = pdfFonts.pdfMake.vfs;
-  pdfMake.vfs = pdfFonts;
+  pdfMake.vfs = pdfFonts.pdfMake.vfs;
+  // pdfMake.vfs = pdfFonts;
# -----

# ビルドする
yarn build

とりあえずの使い方

ファイルおいてサーバ起動
# PDF化したいopen api ファイルを設置(json or yaml)
# {RapiPDFルート}/docs/spec/

# RapiPDFサーバ起動
yarn serve
PDF出力
  • ブラウザで開く
    http://localhost:8080/

  • PDF化したいファイルを指定して GENERATE PDF を押下

スクリーンショット 2022-10-17 10.31.20.png

これで日本語含むOpenAPIドキュメントもPDF出力できる。はず。
もともと入ってたROBOTOフォントも残したい場合はフォントをDLしてフォントファイルを生成すると良い。
https://fonts.google.com/?query=roboto

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?