TppHotPDFDevice

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

 

FastReport adapter  QuickReport adapter  DevExpress adapter

ReportBuilder device class,使用 HotPDF 作為底層 PDF backend,而不是 ReportBuilder 自己的 ppPDFDevice。適用於已嵌入 HotPDF,並希望整個應用程式共用單一 PDF backend 的專案

 

Delphi declaration:

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;

 

說明

TppHotPDFDevice 繼承自 TppGraphicsDevice(位於 TppCustomScreenDevice / TppImageDevice 上一層),因此指定給 TppReport.PrinterDevice 或作為 TppPublisher 的 publisher device 使用時,會接入 ReportBuilder 的 device chain。DeviceName 回報為 'HotPDF'。由於 ReportBuilder 的 device registration 透過 ppRptDeviceMap 而非 RegisterComponents 完成,因此沒有 IDE component palette entry;呼叫端需直接建立 TppHotPDFDevice

 

每個經由 TppGraphicsDevice.ReceivePage 進來的頁面,都會繪製到暫時性的 TMetafileCanvas(在 BeforeRenderPage 建立,在 AfterRenderPage finalise)。擷取到的 TMetafile 接著交給 HotPDF 的 ShowEnhancedMetafile auto-scaling importer:

 

1. StartJob creates the THotPDF instance, sets metadata, and calls BeginDoc.

2. BeforeRenderPage creates a TMetafile sized to spWidth x spHeight plus a TMetafileCanvas, and sets it as the inherited Canvas.

3. RenderPage(inherited)走訪 DrawCommands,並透過 GraphicsContext 將它們導向我們的 metafile canvas

4. AfterRenderPage finalises metafile(釋放 canvas),新增尺寸為 mmWidth x mmHeight(轉換為 PDF points)的 HotPDF page,並透過 ShowEnhancedMetafile 播放 metafile

5. EndJob 呼叫 HotPDF.EndDoc;若輸出是 Stream,則從內部寫出的暫存檔複製 bytes

 

屬性

FileName - target PDF path. Used unless SetOutputStream has installed a stream.

Title / Author / Subject / Keywords - 檔案 metadata。Title 為空時,device 會 fallback 到 FileName,因此 PDF 一定有非空 title

PDFVersion - 檔案應目標的 PDF specification level。預設為 pdf17

Compressed - HotPDF stream compression on (default True). Set False for diagnostic PDFs.

CompressionLevel - FlateDecode level. Defaults to clDefault.

SetOutputStream(AStream) - 將 PDF bytes 導入 AStream,而不是寫入磁碟。請在 report 觸發 StartJob 前呼叫

 

Typical 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;

 

Capabilities preserved

由 ReportBuilder 標準 draw-command pipeline render 的 vector 與 raster page content。GDI-resolved text strings。預設 200 DPI metafile capture(可透過 inherited PixelsPerInch 設定)可提供列印品質輸出,且不會產生過大檔案

 

Limitations of the metafile bridge

由於頁面會擷取為 enhanced metafiles,需要結構資訊的 ReportBuilder-specific PDF features(AcroForm fields、named destinations、outlines、PDF/A 或 PDF/X conformance gates)不會傳遞。輸出會忠實重現 ReportBuilder render 的視覺結果,但不是 structured PDF

 

Packaging note

device 位於 Lib\Addons\ReportBuilder\,且不屬於主要 HotPDF*.dpk packages,因此 ReportBuilder dependency 只會由選用此 device 的專案拉入。smoke test(smoke_pp_hotpdf.dpr)與該 unit 放在同一處

 

請參閱: TfrxHotPDFExport, TQRHotPDFExportFilter, dxHotPDFExportReportLink, THPDFPage.ShowMetafile, Enhanced EMF/WMF Support