|
export filter สำหรับ QuickReport ที่ใช้ HotPDF เป็น PDF backend แทน QRPDFFilter ของ QuickReport เหมาะสำหรับโปรเจกต์ที่ฝัง HotPDF อยู่แล้วและต้องการใช้ PDF backend เดียวกันทั้งแอปพลิเคชัน
Delphi declaration:
type
TQRHotPDFExportFilter = class(TQRExportFilter)
public
constructor Create(Filename: string); override;
procedure SetOutputStream(AStream: TStream);
property Title, Author, Subject, Keywords: string;
property PDFVersion: TPDFVersType;
property Compressed: Boolean;
property CompressionLevel: TPDFCompressionLevel;
end;
คำอธิบาย
TQRHotPDFExportFilter สืบทอดจาก TQRExportFilter จึงเข้ากับ workflow ปกติ MyReport.ExportToFilter(MyExporterInstance) ได้โดยไม่ต้องแก้ QuickReport core เนื่องจาก TQRExportFilter ไม่ใช่ descendant ของ TComponent แต่เป็น plain class ตาม design ของ QuickReport จึงไม่มี IDE component registration และ caller ต้อง instantiate TQRHotPDFExportFilter โดยตรงผ่าน Create('out.pdf')
QuickReport render แต่ละ prepared page เป็น TMetafile ที่ cache ใน QRPrinter.PageList แทนที่จะเขียน callback set ต่อ component ทั้งหมดใหม่ เช่น TextOut / AcceptGraphic / AcceptBand adapter จะ ignore callback เหล่านั้นด้วย no-op overrides และเก็บ per-page metafiles ใน Finish:
1. Start(PaperWidth, PaperHeight, Font) - สร้าง THotPDF instance ตั้ง metadata เรียก BeginDoc และบันทึก (PaperWidth, PaperHeight) เพื่อให้ Finish กำหนดรูปร่าง page ได้ถูกต้อง
2. NewPage / EndPage / TextOut / AcceptGraphic - no-op (the metafile already has the rendered content).
3. Finish - สำหรับ metafile แต่ละรายการใน cache QRPrinter.PageList[i] ให้เพิ่มหรือ reuse หน้า HotPDF ที่มีขนาดตาม PaperWidth / PaperHeight ใน points แล้วเรียก ShowEnhancedMetafile จากนั้นเรียก EndDoc และ release
คุณสมบัติ
Title / Author / Subject / Keywords - document metadata หาก Title ว่าง adapter จะ fallback ไปที่ Filename เพื่อให้ PDF มี title ที่ไม่ว่างเสมอ ให้ตั้งค่าก่อนเรียก ExportToFilter
PDFVersion - 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) - ส่ง PDF bytes เข้า AStream แทนการเขียนลง disk ให้เรียกก่อน report fire StartJob
Typical workflow
Filter := TQRHotPDFExportFilter.Create('Report.pdf');
try
Filter.Title := 'Monthly Statement';
Filter.PDFVersion := pdf17;
QuickRep1.ExportToFilter(Filter);
finally
Filter.Free;
end;
Capabilities preserved
Vector and raster page content rendered by QuickReport's standard preview / printer pipeline. GDI-resolved text strings. Page sizing follows the PaperWidth / PaperHeight handed to Start by QuickReport.
Limitations of the metafile bridge
เนื่องจาก pages ถูกจับเป็น enhanced metafiles ฟีเจอร์ PDF เฉพาะของ QuickReport ที่ต้องใช้ structural information เช่น AcroForm fields, named destinations, outlines, PDF/A หรือ PDF/X conformance gates จะไม่ถูกส่งต่อ output คือการทำซ้ำภาพที่ QuickReport render อย่างถูกต้อง ไม่ใช่ structured PDF
Packaging note
adapter อยู่ใน Lib\Addons\QuickReport\ และไม่เป็นส่วนหนึ่งของ package หลัก HotPDF*.dpk ดังนั้น dependency ของ QuickReport จะถูกดึงเข้ามาเฉพาะโปรเจกต์ที่เลือกใช้ adapter เท่านั้น smoke test (smoke_qr_hotpdf.dpr) อยู่ถัดจาก unit
See also: TfrxHotPDFExport, TppHotPDFDevice, dxHotPDFExportReportLink, THPDFPage.ShowMetafile, Enhanced EMF/WMF Support
|