dxHotPDFExportReportLink

DevExpress ExpressPrinting System 配接器 (Lib\Addons\DevExpress\dxHotPDFExport.pas)

 

FastReport 配接器  QuickReport 配接器  ReportBuilder 裝置

DevExpress ExpressPrinting System(XtraPrinting / XtraReports / cxGrid printable links 等)的 PDF export adapter,使用 HotPDF 作為底層 PDF backend,而不是 DevExpress 自己的 dxPSExportToPDF / TdxPSPDFExport emitter。適用於已嵌入 HotPDF,並希望整個應用程式共用單一 PDF backend 的專案

 

選項記錄:

type

  TdxHotPDFExportOptions = record

    Title, Author, Subject, Keywords: string;

    PDFVersion : TPDFVersType;  // default pdf17

    PDFACompliance: string;

    PDFXCompliance: string;

    Compression: TPDFCompressionLevel;  // default clDefault

    RenderDPI  : Integer;  // default 200

  end;

 

function dxHotPDFDefaultOptions: TdxHotPDFExportOptions;

 

File-based entry points:

function dxHotPDFExportReportLinkToFile(

  AReportLink: TBasedxReportLink;

  const AOutputFileName: string;

  const AOptions: TdxHotPDFExportOptions): Boolean; overload;

function dxHotPDFExportReportLinkToFile(

  AReportLink: TBasedxReportLink;

  const AOutputFileName: string): Boolean; overload;

 

Stream-based entry points:

function dxHotPDFExportReportLinkToStream(

  AReportLink: TBasedxReportLink;

  AOutputStream: TStream;

  const AOptions: TdxHotPDFExportOptions): Boolean; overload;

function dxHotPDFExportReportLinkToStream(

  AReportLink: TBasedxReportLink;

  AOutputStream: TStream): Boolean; overload;

 

說明

DevExpress 的 printing system 以 TBasedxReportLink 為中心,這是把可列印元件(cxGrid、cxRichEdit、cxScheduler、cxPivotGrid 等)連接到 TdxComponentPrinter 的抽象 link。印表機 / link 會組成頁面,然後公開受保護的 PaintPage(ACanvas, APageBounds, APageIndex, AContinuousIndex, AZoomFactor) 方法,把單一頁面繪製到任意 TCanvas。

 

此 adapter 沿用 DevExpress 自家 TdxPSPDFReportExportProvider.Build 的迴圈,但不把 PaintPage 的輸出送進 DevExpress 的 PDF canvas,而是送進 TMetafileCanvas。產生的 metafile 接著交給 HotPDF 的 ShowEnhancedMetafile 自動縮放匯入器:

 

1. 呼叫端以備妥的 TBasedxReportLink 呼叫 dxHotPDFExportReportLinkToFile 或 dxHotPDFExportReportLinkToStream

2. adapter 會呼叫 AReportLink.RebuildReport 來排版頁面

3. 對每個頁面索引,它會向 link 取得 RenderInfo.GetActualPageRenderInfo,以 PDF points 計算頁面尺寸(採用 DevExpress 自己的 PointsPerInch / UnitsPerInch 比例),依選定的 render DPI 建立 TMetafile,再透過 PaintPage(MetaCanvas, ...) 繪製該頁

4. 新增一個 HotPDF 頁面(或重複使用自動建立的第一頁),尺寸設為計算出的 points 尺寸,然後透過 ShowEnhancedMetafile 播放該 metafile

5. HotPDF.EndDoc 寫出 PDF;使用 stream 多載時,接著把暫存檔複製到呼叫端提供的 TStream

 

選項

Title / Author / Subject / Keywords - 文件 metadata。Title 為空時,adapter 會退回 AReportLink.ReportTitle.Text,再退回 AReportLink.Name,因此 PDF 一定有非空 title

PDFVersion - 文件應目標的 PDF specification level。預設為 pdf17

PDFACompliance 與 PDFXCompliance - 把 HotPDF 的標準合規閘門帶進產生的報告 PDF。在依賴最終合規宣告之前,呼叫端仍需透過一般 HotPDF 工作流程備妥所需的 ICC profile、OutputIntent、標記或印前資產

Compression - FlateDecode level。預設為 clDefault

RenderDPI - 透過 TMetafileCanvas 點陣化每頁時使用的像素密度。值越高,文字與線條越銳利,但 metafile 與 PDF 越大。200(預設值)可提供列印品質結果,且不會產生過大檔案。≤ 0 的值會 clamp 到 200

 

典型工作流程

 

dxComponentPrinter1.CurrentLink := cxGridReportLink1;

dxHotPDFExportReportLinkToFile(cxGridReportLink1, 'Grid.pdf');

 

或以自訂選項:

 

Opts := dxHotPDFDefaultOptions;

Opts.Title := 'Q1 Sales';

Opts.PDFACompliance := '3B';

Opts.RenderDPI := 300;

dxHotPDFExportReportLinkToFile(cxGridReportLink1, 'Grid.pdf', Opts);

 

支援的 link 家族

任何 TBasedxReportLink descendant。這涵蓋 cxGrid、cxRichEdit、cxScheduler、cxPivotGrid,以及任何自同一 base class 衍生的 custom links。adapter 不依賴特定 link 類型,因為 PaintPage 合約定義在 base 上

 

保留的能力

每個 DevExpress link 家族(cxGrid、cxScheduler、cxRichEdit、cxPivotGrid、自訂 link)輸出的向量與點陣頁面內容。GDI 解析後的文字字串(DevExpress 透過 TCanvas 轉譯文字;metafile 會忠實記錄 GDI 文字呼叫)

 

限制

由於頁面會擷取為 enhanced metafiles,需要結構資訊的 DevExpress-specific PDF features(interactive AcroForm fields、named destinations、bookmarks / outlines)不會傳遞。PDF/A 與 PDF/X 選項欄位會轉給 HotPDF,但 OutputIntent profiles 等標準專屬資產仍由呼叫端負責。輸出是 DevExpress render 內容的忠實視覺重現,而不是 structured PDF

 

封裝說明

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

 

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