TppHotPDFDevice

ReportBuilder adapter (Lib\Addons\ReportBuilder\ppHotPDFDevice.pas)

 

FastReport adapter  QuickReport adapter  DevExpress adapter

ReportBuilder 用 device class です。ReportBuilder 独自の ppPDFDevice の代わりに、基盤の PDF backend として HotPDF を使用します。すでに HotPDF を組み込んでおり、アプリケーション全体で単一の PDF backend を使いたいプロジェクト向けです

 

Delphi 宣言:

type

  TppHotPDFDevice = class(TppGraphicsDevice)

  public

    class function DeviceName: String; override;

    procedure StartJob; override;

    procedure EndJob; override;

    procedure CancelJob; override;

    procedure SetOutputStream(AStream: TStream);

    property FileName: string;

    property Title, Author, Subject, Keywords: string;

    property PDFVersion: TPDFVersType;

    property Compressed: Boolean;

    property CompressionLevel: TPDFCompressionLevel;

  end;

 

説明

TppHotPDFDeviceTppGraphicsDevice から派生しています (TppCustomScreenDevice / TppImageDevice の 1 階層上)。そのため TppReport.PrinterDevice に割り当てるか TppPublisher の publisher device として使うと、ReportBuilder の device chain に組み込めます。DeviceName'HotPDF' として報告されます。ReportBuilder の device registration は RegisterComponents ではなく ppRptDeviceMap 経由で行われるため、IDE component palette entry はありません。呼び出し元が TppHotPDFDevice を直接 instantiate します

 

TppGraphicsDevice.ReceivePage を通って来る各ページは、一時的な TMetafileCanvas (BeforeRenderPage で作成され、AfterRenderPage で finalise されます) に描画されます。キャプチャされた TMetafile は HotPDF の ShowEnhancedMetafile auto-scaling importer に渡されます:

 

1. StartJobTHotPDF instance を作成し、metadata を設定して BeginDoc を呼び出します

2. BeforeRenderPagespWidth x spHeight に合わせた TMetafileTMetafileCanvas を作成し、それを inherited Canvas として設定します

3. inherited の RenderPageDrawCommands を走査し、GraphicsContext 経由でそれらをこの metafile canvas に送ります

4. AfterRenderPage は metafile を finalise し (canvas を解放)、mmWidth x mmHeight から PDF point に変換したサイズで新しい HotPDF ページを追加し、ShowEnhancedMetafile 経由で metafile を再生します

5. EndJobHotPDF.EndDoc を呼び出します。出力先が Stream の場合は、内部で書き込まれた temp file から bytes をコピーします

 

プロパティ

FileName - target PDF path です。SetOutputStream が stream を設定していない場合に使用されます

Title / Author / Subject / Keywords - document metadata です。Title が空の場合、adapter は Report.Name にフォールバックするため、PDF は常に空でない title を持ちます

PDFVersion - ドキュメントが対象とする PDF 仕様レベルです。既定値は pdf17 です

Compressed - HotPDF stream compression を有効にします (既定値は True)。診断用 PDF が必要な場合は False に設定します (ファイルサイズは約 5 倍になります)

CompressionLevel - FlateDecode level です。既定値は clDefault です

SetOutputStream(AStream) - PDF bytes を disk に書き込む代わりに AStream に送ります。report が StartJob を発火する前に呼び出してください

 

典型的な workflow

 

Dev := TppHotPDFDevice.Create(nil);

try

  Dev.FileName := 'Report.pdf';

  Dev.Title := 'Monthly Statement';

  Dev.PDFVersion := pdf17;

  ppReport1.DeviceType := 'HotPDF';

  ppReport1.PrinterDevice := Dev;

  ppReport1.Print;

finally

  Dev.Free;

end;

 

保持される機能

ReportBuilder の標準 draw-command pipeline がレンダリングする vector および raster page content。GDI で解決された text string。既定の 200 DPI metafile capture (inherited PixelsPerInch で設定可能) により、巨大なファイルにせず印刷品質の出力が得られます

 

metafile bridge の制限

ページは enhanced metafile としてキャプチャされるため、構造情報を必要とする ReportBuilder 固有の PDF 機能 (AcroForm fields, named destinations, outlines, PDF/A または PDF/X conformance gates) は引き継がれません。出力は ReportBuilder がレンダリングする内容の忠実な視覚的再現であり、構造化 PDF ではありません

 

パッケージング上の注意

device は Lib\Addons\ReportBuilder\ にあり、メインの HotPDF*.dpk packages には含まれません。そのため ReportBuilder 依存関係は、device を明示的に使用するプロジェクトにのみ取り込まれます。smoke test (smoke_pp_hotpdf.dpr) は unit の隣にあります

 

関連項目: TfrxHotPDFExport, TQRHotPDFExportFilter, dxHotPDFExportReportLink, THPDFPage.ShowMetafile, Enhanced EMF/WMF Support