dxHotPDFExportReportLink

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

 

FastReport adapter  QuickReport adapter  ReportBuilder device

DevExpress ExpressPrinting System(XtraPrinting / XtraReports / cxGrid 可打印链接等)PDF 导出适配器,使用 HotPDF 作为底层 PDF 后端,替代 DevExpress 自带的 dxPSExportToPDF / TdxPSPDFExport 输出器。适用于已嵌入 HotPDF、想让整个应用共用同一个 PDF 后端的项目。

 

选项 record:

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 的打印体系围绕 TBasedxReportLink 展开 - 这个抽象链接把可打印组件(cxGrid、cxRichEdit、cxScheduler、cxPivotGrid 等)桥接到 TdxComponentPrinter。printer / link 先组合页面,再暴露受保护的 PaintPage(ACanvas, APageBounds, APageIndex, AContinuousIndex, AZoomFactor) 方法,把单页画到任意 TCanvas 上。

 

该适配器复刻了 DevExpress 自家 TdxPSPDFReportExportProvider.Build 的循环,但不是把 PaintPage 的输出送进 DevExpress PDF canvas,而是送进 TMetafileCanvas。得到的图元文件再交给 HotPDF 的 ShowEnhancedMetafile 自动缩放导入器:

 

1. 调用方携带准备好的 TBasedxReportLink 调用dxHotPDFExportReportLinkToFile 或 dxHotPDFExportReportLinkToStream,携带准备好的 TBasedxReportLink。

2. The adapter calls AReportLink.RebuildReport to compose pages.

3. 对每个页面索引,向 link 请求 RenderInfo.GetActualPageRenderInfo,用 DevExpress 自身的 PointsPerInch / UnitsPerInch 比率算出 PDF 点数下的页面大小,按选定渲染 DPI 构建 TMetafile,再经 PaintPage(MetaCanvas, ...) 渲染该页。

4. 新增一个 HotPDF 页面(或复用自动创建的第一页),按算出的点数尺寸设定大小,然后经 ShowEnhancedMetafile 播放图元文件。

5. HotPDF.EndDoc 写出 PDF;流重载随后把临时文件复制进调用方提供的 TStream。

 

选项

Title / Author / Subject / Keywords - 文档元数据。Title 为空时,适配器先回退到 AReportLink.ReportTitle.Text,再回退到 AReportLink.Name,保证 PDF 始终有非空标题。

PDFVersion - 文档应采用的 PDF 规范级别。默认为 pdf17。

PDFACompliance 与 PDFXCompliance - 把 HotPDF 的标准合规门控传递到生成的报表 PDF。在依赖最终合规声明之前,调用方仍需按常规 HotPDF 工作流准备好所需的 ICC profile、OutputIntent、tagging 或印前资产。

Compression - FlateDecode level. Defaults to clDefault.

RenderDPI - 经 TMetafileCanvas 栅格化每一页时使用的像素密度。值越高,文字和线条越清晰,但图元文件和 PDF 越大。200(默认)在不产生巨大文件的前提下给出打印级质量。≤ 0 的值会被钳制到 200。

 

典型工作流

 

dxComponentPrinter1.CurrentLink := cxGridReportLink1;

dxHotPDFExportReportLinkToFile(cxGridReportLink1, 'Grid.pdf');

 

Or with custom options:

 

Opts := dxHotPDFDefaultOptions;

Opts.Title := 'Q1 Sales';

Opts.PDFACompliance := '3B';

Opts.RenderDPI := 300;

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

 

支持的 link 类型族

的任意后代。TBasedxReportLink 的任意后代。涵盖 cxGrid、cxRichEdit、cxScheduler、cxPivotGrid,以及派生自同一基类的自定义链接。适配器不依赖具体的 link 类型,因为 PaintPage 契约定义在基类上。

 

保留的能力

每个 DevExpress link 类型族(cxGrid、cxScheduler、cxRichEdit、cxPivotGrid、自定义链接)输出的矢量和光栅页面内容。GDI 解析后的文本字符串(DevExpress 经 TCanvas 渲染文本;图元文件忠实记录 GDI 文本调用)。

 

限制 of the metafile bridge

由于页面以增强型图元文件捕获,需要结构信息的 DevExpress 专用 PDF 功能(交互式 AcroForm 字段、命名目标、书签 / 大纲)不会被传递。PDF/A 和 PDF/X 选项字段会转发给 HotPDF,但 OutputIntent profile 等标准专用资产仍由调用方负责。输出是对 DevExpress 渲染结果的忠实视觉再现,不是结构化 PDF。

 

打包说明

适配器位于 Lib\Addons\DevExpress\,不属于主 HotPDF*.dpk 包,因此只有显式选用该适配器的项目才会引入 DevExpress ExpressPrinting 依赖。烟雾测试(smoke_dx_hotpdf.dpr)与该单元放在同一位置。

 

另请参阅: TfrxHotPDFExport, TQRHotPDFExportFilter, TppHotPDFDevice, THPDFPage.ShowMetafile, 增强型 EMF/WMF 支持