作成日: 2019/12/24 最終更新日: 2024/07/19
文書種別
使用方法
詳細
ActiveReportsJSのPDFエクスポート機能では、サーバーに配置したフォントをPDFに埋め込むことができます。
具体的な手順は以下の通りです。
-
フォントファイルを配置する
アプリケーションのルートディレクトリ直下にfontsフォルダを作成し、フォントファイルを配置します。
|- fonts | |- font1.ttf | |- font2.ttc | |- reports | |- report1.rdlx-json | |- index.html(ビューワを配置しているページ)
-
フォント記述子を定義する
フォント記述子は以下のプロパティで構成されます。
name フォント名(デザイナで設定した名称) 必須 source フォントファイルのパス 必須 postscriptName フォントのポストスクリプト名 任意(ttcファイルの場合は必須)
◆サンプルコード(JavaScript)
const fonts = [ {name: 'IPAゴシック', source: '/fonts/ipag.ttc', postscriptName: 'IPAGothic'}, {name: 'IPA明朝', source: '/fonts/ipam.ttc', postscriptName: 'IPAMincho'} ];
以下の形式でJSONファイル(fontsConfig.json)に保存することもできます。
{ "descriptors": [ { "name": "IPAゴシック", "source": "/fonts/ipag.ttc", "postscriptName": "IPAGothic" }, { "name": "IPA明朝", "source": "/fonts/ipam.ttc", "postscriptName": "IPAMincho" } ] }
- フォント記述子を登録する
registerFontsメソッドを使用してフォント記述子を登録します。
const Core = MESCIUS.ActiveReportsJS.Core; const PdfExport = MESCIUS.ActiveReportsJS.PdfExport; // コードで定義したフォント記述子を登録する場合 await Core.FontStore.registerFonts(...fonts); // JSONファイルから読み込む場合 await Core.FontStore.registerFonts("/fonts/fontsConfig.json"); // PDFエクスポート const pageReport = new Core.PageReport(); await pageReport.load("/reports/report1.rdlx-json"); const pageDocument = await pageReport.run(); const result = await PdfExport.exportDocument(pageDocument); result.download("filename");