|
ReportBuilder 设备类,使用 HotPDF 作为底层 PDF 后端,而不是 ReportBuilder 自带的 ppPDFDevice。适用于已经嵌入 HotPDF,并希望整个应用共用同一个 PDF 后端的项目
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 上作为发布设备使用时,即可接入 ReportBuilder 的设备链。DeviceName 报告为 'HotPDF'。ReportBuilder 的设备注册走的是 ppRptDeviceMap 而非 RegisterComponents,因此 IDE 组件面板里没有条目 - 调用方直接实例化 TppHotPDFDevice。
经 TppGraphicsDevice.ReceivePage 传入的每个页面,都会绘制到一个临时的 TMetafileCanvas 上(在 BeforeRenderPage 中创建,在 AfterRenderPage 中结束)。捕获到的 TMetafile 随后交给 HotPDF 的 ShowEnhancedMetafile 自动缩放导入器:
1. StartJob creates the THotPDF instance, sets metadata, and calls BeginDoc.
2. BeforeRenderPage 创建一个 TMetafile(大小为 spWidth x spHeight)以及对应的 TMetafileCanvas,并将其设为继承的 Canvas
3. RenderPage(继承)遍历 DrawCommands,经 GraphicsContext 画到我们的图元文件 canvas 上。
4. AfterRenderPage 定稿图元文件(释放 canvas),新增一个按 mmWidth x mmHeight(换算为 PDF 点)设定大小的 HotPDF 页面,然后要么经 ShowEnhancedMetafile 播放图元文件,要么在 RenderMode 为 hprmNativeDrawCommands 时原生输出受支持的绘制命令。
5. EndJob 调用 HotPDF.EndDoc;输出为 Stream 时,从内部写出的临时文件复制字节。
属性
FileName - target PDF path. Used unless SetOutputStream has installed a stream.
Title / Author / Subject / Keywords - 文档元数据。Title 为空时,设备回退到 FileName,保证 PDF 始终有非空标题。
PDFVersion - 文档应采用的 PDF 规范级别。默认为 pdf17。
PDFACompliance 与 PDFXCompliance - 把 HotPDF 的标准合规门控传递到生成的报表 PDF。在依赖最终合规声明之前,调用方仍需按常规 HotPDF 工作流准备好所需的 ICC profile、OutputIntent、tagging 或印前资产。
Compressed - 是否启用 HotPDF 流压缩(默认 True)。诊断用 PDF 可设为 False
CompressionLevel - FlateDecode level. Defaults to clDefault.
RenderMode - 默认 hprmPageMetafile,走原有的视觉桥。设为 hprmNativeDrawCommands 时,把受支持的 ReportBuilder 绘制命令直接映射为 HotPDF 的文本、矢量、图像和 URI 链接操作。包含不受支持命令的页面自动回退到图元文件桥。
SetOutputStream(AStream) - 把 PDF 字节路由进 AStream 而不是写盘。请在报表触发 StartJob 之前调用。
典型工作流
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;
保留的能力
保留 ReportBuilder 标准绘图命令流程渲染的矢量和光栅页面内容,以及 GDI 解析后的文本字符串。默认 200 DPI 图元文件捕获可通过继承的 PixelsPerInch 配置,在不生成巨大文件的情况下获得打印质量输出
限制 of the metafile bridge
由于页面以增强型图元文件捕获,需要结构信息的 ReportBuilder 专用 PDF 功能(AcroForm 字段、命名目标和大纲)不会被传递。PDF/A 和 PDF/X 门控属性会转发给 HotPDF,但 OutputIntent profile 等标准专用资产仍由调用方负责。 原生绘制命令模式当前覆盖 ReportBuilder 常见的绘制命令集;页面包含不受支持的命令(如复杂的自定义渲染器或渐变)时,会主动回退到图元文件桥,宁可保全视觉输出,也不半途输出一页。
打包说明
该设备位于 Lib\Addons\ReportBuilder\,不属于主 HotPDF*.dpk 包,因此只有显式使用该设备的项目才会引入 ReportBuilder 依赖。烟雾测试 (smoke_pp_hotpdf.dpr) 与该单元放在同一位置
另请参阅: TfrxHotPDFExport, TQRHotPDFExportFilter, dxHotPDFExportReportLink, THPDFPage.ShowMetafile, 增强型 EMF/WMF 支持
|