|
ReportBuilder device class that uses HotPDF as the underlying PDF backend instead of ReportBuilder's own ppPDFDevice. Intended for projects that already embed HotPDF and want a single PDF backend across the whole application.
Delphi declaration:
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 Compressed: Boolean;
property CompressionLevel: TPDFCompressionLevel;
end;
Description
TppHotPDFDevice descends from TppGraphicsDevice (one level above TppCustomScreenDevice / TppImageDevice), so it slots into ReportBuilder's device chain when assigned to TppReport.PrinterDevice or used as a publisher device on a TppPublisher. DeviceName is reported as 'HotPDF'. Because device registration in ReportBuilder is done via ppRptDeviceMap rather than RegisterComponents, there is no IDE component palette entry - callers instantiate TppHotPDFDevice directly.
Each page coming through TppGraphicsDevice.ReceivePage is drawn onto a transient TMetafileCanvas (created in BeforeRenderPage, finalised in AfterRenderPage). The captured TMetafile is then fed to HotPDF's ShowEnhancedMetafile auto-scaling importer:
1. StartJob creates the THotPDF instance, sets metadata, and calls BeginDoc.
2. BeforeRenderPage creates a TMetafile sized to spWidth x spHeight plus a TMetafileCanvas, and sets it as the inherited Canvas.
3. RenderPage (inherited) walks the DrawCommands and routes them through the GraphicsContext onto our metafile canvas.
4. AfterRenderPage finalises the metafile (free canvas), adds a new HotPDF page sized to mmWidth x mmHeight (converted to PDF points), and plays the metafile via ShowEnhancedMetafile.
5. EndJob calls HotPDF.EndDoc; if the output is a Stream, copies bytes from the temp file written internally.
Properties
FileName - target PDF path. Used unless SetOutputStream has installed a stream.
Title / Author / Subject / Keywords - document metadata. When Title is empty the device falls back to FileName so the PDF always has a non-empty title.
PDFVersion - the PDF specification level the document should target. Defaults to pdf17.
Compressed - HotPDF stream compression on (default True). Set False for diagnostic PDFs.
CompressionLevel - FlateDecode level. Defaults to clDefault.
SetOutputStream(AStream) - route the PDF bytes into AStream instead of writing to disk. Call before the report fires StartJob.
Typical workflow
Dev := TppHotPDFDevice.Create(nil);
try
Dev.FileName := 'Report.pdf';
Dev.Title := 'Monthly Statement';
Dev.PDFVersion := pdf17;
ppReport1.DeviceType := 'HotPDF';
ppReport1.PrinterDevice := Dev;
ppReport1.Print;
finally
Dev.Free;
end;
Capabilities preserved
Vector and raster page content rendered by ReportBuilder's standard draw-command pipeline. GDI-resolved text strings. Default 200 DPI metafile capture (configurable via the inherited PixelsPerInch) gives print-quality output without enormous files.
Limitations of the metafile bridge
Because pages are captured as enhanced metafiles, ReportBuilder-specific PDF features that require structural information (AcroForm fields, named destinations, outlines, PDF/A or PDF/X conformance gates) are not propagated. The output is a faithful visual reproduction of what ReportBuilder renders, not a structured PDF.
Packaging note
The device lives in Lib\Addons\ReportBuilder\ and is not part of the main HotPDF*.dpk packages, so the ReportBuilder dependency is only pulled in by projects that opt in to the device. A smoke test (smoke_pp_hotpdf.dpr) lives alongside the unit.
See also: TfrxHotPDFExport, TQRHotPDFExportFilter, dxHotPDFExportReportLink, THPDFPage.ShowMetafile, Enhanced EMF/WMF Support
|