|
QuickReport export filter,使用 HotPDF 作為底層 PDF backend,而不是 QuickReport 自己的 QRPDFFilter。適用於已嵌入 HotPDF,並希望整個應用程式共用單一 PDF backend 的專案
Delphi 宣告:
type
TQRHotPDFExportFilter = class(TQRExportFilter)
public
constructor Create(Filename: string); override;
procedure SetOutputStream(AStream: TStream);
property Title, Author, Subject, Keywords: string;
property PDFVersion: TPDFVersType;
property PDFACompliance: string;
property PDFXCompliance: string;
property Compressed: Boolean;
property CompressionLevel: TPDFCompressionLevel;
end;
說明
TQRHotPDFExportFilter 繼承自 TQRExportFilter,因此不需修改 QuickReport core,即可接入一般 MyReport.ExportToFilter(MyExporterInstance) workflow。由於 TQRExportFilter 不是 TComponent descendant(在 QuickReport 設計中是 plain class),因此沒有 IDE component registration;呼叫端需直接透過 Create('out.pdf') 建立 TQRHotPDFExportFilter
QuickReport 會把每個已備妥的頁面 render 成快取在 QRPrinter.PageList 的 TMetafile。adapter 不重新實作整套 per-component 的 TextOut / AcceptGraphic / AcceptBand callback set,而是忽略它們(no-op overrides),並在 Finish 中收集各頁 metafiles:
1. Start(PaperWidth, PaperHeight, Font) - 建立 THotPDF instance、設定 metadata、呼叫 BeginDoc,並儲存 (PaperWidth, PaperHeight),讓 Finish 可正確 shaping pages
2. NewPage / EndPage / TextOut / AcceptGraphic - no-op(metafile 已包含 render 後的內容)。
3. Finish - 對每個快取的 QRPrinter.PageList[i] metafile,加入(或重用)尺寸為 PaperWidth / PaperHeight points 的 HotPDF 頁面,並呼叫 ShowEnhancedMetafile。接著 EndDoc 並釋放。
屬性
Title / Author / Subject / Keywords - 文件 metadata。Title 為空時,adapter 會退回 Filename,確保 PDF 一定有非空 title。請在呼叫 ExportToFilter 前設定。
PDFVersion - 檔案應目標的 PDF specification level。預設為 pdf17。
PDFACompliance 與 PDFXCompliance - 把 HotPDF 的標準合規閘門帶進產生的報告 PDF。在依賴最終合規宣告之前,呼叫端仍需透過一般 HotPDF 工作流程備妥所需的 ICC profile、OutputIntent、標記或印前資產。
Compressed - HotPDF stream compression on (default True). Set False for diagnostic PDFs.
CompressionLevel - FlateDecode level. Defaults to clDefault.
SetOutputStream(AStream) - 將 PDF bytes 導入 AStream,而不是寫入磁碟。請在 ExportToFilter 前呼叫。內部會使用暫存檔,因為 HotPDF 在 EndDoc 時儲存;bytes 會在 Finish 中串流回去
Typical workflow
Filter := TQRHotPDFExportFilter.Create('Report.pdf');
try
Filter.Title := 'Monthly Statement';
Filter.PDFVersion := pdf17;
Filter.PDFACompliance := '3B';
QuickRep1.ExportToFilter(Filter);
finally
Filter.Free;
end;
Capabilities preserved
Vector and raster page content rendered by QuickReport's standard preview / printer pipeline. GDI-resolved text strings. Page sizing follows the PaperWidth / PaperHeight handed to Start by QuickReport.
Limitations of the metafile bridge
由於頁面會擷取為 enhanced metafiles,需要結構資訊的 QuickReport-specific PDF features(AcroForm fields、named destinations、outlines)不會傳遞。PDF/A 與 PDF/X 的閘門屬性會轉給 HotPDF,但 OutputIntent profiles 等標準專屬資產仍由呼叫端負責。輸出是 QuickReport render 內容的忠實視覺重現,而不是 structured PDF
Packaging note
adapter 位於 Lib\Addons\QuickReport\,且不屬於主要 HotPDF*.dpk packages,因此 QuickReport dependency 只會由選用此 adapter 的專案拉入。smoke test(smoke_qr_hotpdf.dpr)與該 unit 放在同一處
請參閱: TfrxHotPDFExport, TppHotPDFDevice, dxHotPDFExportReportLink, THPDFPage.ShowMetafile, Enhanced EMF/WMF Support
|