|
ReportBuilder device class,使用 HotPDF 作為底層 PDF backend,而不是 ReportBuilder 自己的 ppPDFDevice。適用於已嵌入 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 PDFACompliance: string;
property PDFXCompliance: string;
property Compressed: Boolean;
property CompressionLevel: TPDFCompressionLevel;
property RenderMode: TppHotPDFRenderMode;
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 定稿)。擷取到的 TMetafile 接著交給 HotPDF 的 ShowEnhancedMetafile auto-scaling importer:
1. StartJob 會建立 THotPDF 實例、設定 metadata,並呼叫 BeginDoc。
2. BeforeRenderPage 會建立尺寸為 spWidth x spHeight 的 TMetafile 與對應的 TMetafileCanvas,並把它設為繼承的 Canvas。
3. RenderPage(inherited)走訪 DrawCommands,並透過 GraphicsContext 將它們導向我們的 metafile canvas。
4. AfterRenderPage 會定稿 metafile(釋放 canvas),新增尺寸為 mmWidth x mmHeight(換算為 PDF points)的 HotPDF page,然後在 RenderMode 為 hprmNativeDrawCommands 時改以原生方式輸出支援的繪製命令,否則透過 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 會退回 FileName,因此 PDF 一定有非空 title
PDFVersion - 檔案應目標的 PDF specification level。預設為 pdf17
PDFACompliance 與 PDFXCompliance - 把 HotPDF 的標準合規閘門傳遞到產生的報表 PDF。在依賴最終合規宣告之前,呼叫端仍須透過一般 HotPDF 工作流程備妥所需的 ICC profile、OutputIntent、tagging 或印前資產。
Compressed - 是否啟用 HotPDF 串流壓縮(預設 True)。診斷用的 PDF 可設為 False。
CompressionLevel - FlateDecode 壓縮等級。預設為 clDefault。
RenderMode - 預設為 hprmPageMetafile,走原本的視覺橋接。設為 hprmNativeDrawCommands 時,會把支援的 ReportBuilder 繪製命令直接對應到 HotPDF 的文字、向量、影像與 URI 連結操作。含不支援命令的頁面會自動退回 metafile 橋接。
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;
Dev.PDFACompliance := '3B';
Dev.RenderMode := hprmNativeDrawCommands;
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 設定)可提供列印品質輸出,且不會產生過大檔案。原生 draw-command 模式會在頁面只含支援的命令時,把常見的文字、圖形、線條、影像與 URI 超連結命令直接對應到 HotPDF 頁面操作。
Limitations of the metafile bridge
由於頁面會擷取為 enhanced metafiles,需要結構資訊的 ReportBuilder-specific PDF features(AcroForm fields、named destinations、outlines)不會傳遞。PDF/A 與 PDF/X 的閘門屬性會轉給 HotPDF,但 OutputIntent profiles 等標準專屬資產仍由呼叫端負責。
原生 draw-command 模式目前涵蓋常見的 ReportBuilder 繪製命令集,對含不支援命令(例如複雜的自訂 renderer 或漸層)的頁面會刻意退回 metafile 橋接,以保留視覺輸出,而不是只輸出頁面的一部分
Packaging note
device 位於 Lib\Addons\ReportBuilder\,且不屬於主要 HotPDF*.dpk packages,因此 ReportBuilder dependency 只會由選用此 device 的專案拉入。smoke test(smoke_pp_hotpdf.dpr)與該 unit 放在同一處
See also: TfrxHotPDFExport, TQRHotPDFExportFilter, dxHotPDFExportReportLink, THPDFPage.ShowMetafile, Enhanced EMF/WMF Support
|