|
device class สำหรับ ReportBuilder ที่ใช้ HotPDF เป็น PDF backend แทน ppPDFDevice ของ ReportBuilder เหมาะสำหรับโปรเจกต์ที่ฝัง HotPDF อยู่แล้วและต้องการใช้ PDF backend เดียวกันทั้งแอปพลิเคชัน
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;
คำอธิบาย
TppHotPDFDevice สืบทอดจาก TppGraphicsDevice ซึ่งอยู่เหนือ TppCustomScreenDevice / TppImageDevice หนึ่งระดับ จึงเข้ากับ device chain ของ ReportBuilder เมื่อ assign ให้ TppReport.PrinterDevice หรือใช้เป็น publisher device บน TppPublisher ค่า DeviceName รายงานเป็น 'HotPDF' เนื่องจาก device registration ใน ReportBuilder ทำผ่าน ppRptDeviceMap ไม่ใช่ RegisterComponents จึงไม่มี IDE component palette entry และ caller ต้อง instantiate TppHotPDFDevice โดยตรง
แต่ละ page ที่ผ่าน TppGraphicsDevice.ReceivePage จะถูกวาดลงบน TMetafileCanvas ชั่วคราว ซึ่งสร้างใน BeforeRenderPage และ finalise ใน AfterRenderPage จากนั้น TMetafile ที่จับได้จะถูกส่งเข้า auto-scaling importer ShowEnhancedMetafile ของ HotPDF:
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. inherited RenderPage เดินผ่าน DrawCommands และ route ผ่าน GraphicsContext ไปยัง metafile canvas ของเรา
4. AfterRenderPage finalise metafile โดย free canvas เพิ่มหน้า HotPDF ใหม่ที่มีขนาดตาม mmWidth x mmHeight ซึ่งแปลงเป็น PDF points แล้วเล่น metafile ผ่าน ShowEnhancedMetafile
5. EndJob เรียก HotPDF.EndDoc ถ้า output เป็น Stream จะคัดลอก bytes จาก temp file ที่เขียนภายใน
คุณสมบัติ
FileName - target PDF path. Used unless SetOutputStream has installed a stream.
Title / Author / Subject / Keywords - document metadata หาก Title ว่าง device จะ fallback ไปที่ FileName เพื่อให้ PDF มี title ที่ไม่ว่างเสมอ
PDFVersion - ระดับ PDF specification ที่ document ควร target ค่าเริ่มต้นคือ pdf17
Compressed - HotPDF stream compression on (default True). Set False for diagnostic PDFs.
CompressionLevel - FlateDecode level. Defaults to clDefault.
SetOutputStream(AStream) - ส่ง PDF bytes เข้า AStream แทนการเขียนลง disk ให้เรียกก่อน report fire 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 และ raster page content ที่ render โดย draw-command pipeline มาตรฐานของ ReportBuilder รวมถึง text strings ที่ GDI resolve แล้ว การจับ metafile ที่ 200 DPI ตามค่าเริ่มต้น ซึ่งปรับได้ผ่าน inherited PixelsPerInch ให้ output ระดับ print-quality โดยไม่ทำให้ไฟล์ใหญ่มาก
Limitations of the metafile bridge
เนื่องจาก pages ถูกจับเป็น enhanced metafiles ฟีเจอร์ PDF เฉพาะของ ReportBuilder ที่ต้องใช้ structural information เช่น AcroForm fields, named destinations, outlines, PDF/A หรือ PDF/X conformance gates จะไม่ถูกส่งต่อ output คือการทำซ้ำภาพที่ ReportBuilder render อย่างถูกต้อง ไม่ใช่ structured PDF
Packaging note
device อยู่ใน Lib\Addons\ReportBuilder\ และไม่เป็นส่วนหนึ่งของ package หลัก HotPDF*.dpk ดังนั้น dependency ของ ReportBuilder จะถูกดึงเข้ามาเฉพาะโปรเจกต์ที่เลือกใช้ device เท่านั้น smoke test (smoke_pp_hotpdf.dpr) อยู่ถัดจาก unit
See also: TfrxHotPDFExport, TQRHotPDFExportFilter, dxHotPDFExportReportLink, THPDFPage.ShowMetafile, Enhanced EMF/WMF Support
|