TDBGrid export support
The dbGridHotPDFExport add-on unit (Lib\addons\DBGrid) writes a TDBGrid dataset's visible columns and every row into a PDF table. It creates, fills and saves its own THotPDF document, so the grid is the sole input it needs
Entry points
DBGridHotPDFExportToFile(AGrid, AOutputFileName[, AOptions])writes the PDF out to a fileDBGridHotPDFExportToStream(AGrid, AOutputStream[, AOptions])writes it to a stream, via a temporary file under%TEMP%DBGridHotPDFDefaultOptionshands back aTDBGridHotPDFExportOptionsrecord carrying the defaults: A4 in points (595 x 842), 36-point margins, 22-point rows, a 24-point header row, Arial 9 with a 14-point title, aclBtnFaceheader and$00F5F5F5alternate rowsTDBGridHotPDFExportis the same export packaged as a component on the HotPDF palette page (registered bydbGridHotPDFDesign): setGridandOutputFileName, then callExportToFileorExportToStream. Every option field is a published property;ResetOptionsputs the defaults back
What is exported
- Visible grid columns that have a field, in grid order and with their title captions, or the dataset's visible fields when the grid has no columns; column widths keep the grid's proportions across the printable width
- Every record from
FirsttoEof, using each field'sDisplayText; cell text that will not fit is cut and ends in... - All text uses
FontName, which must carry glyphs for the data: the default Arial shows Chinese, Japanese or Korean text as empty boxes, so set a CJK font such as Microsoft YaHei for such data - A new page starts when the next row would cross the bottom margin, and the header row repeats on every page. The title (
Title, else the grid'sName) is drawn once, on the first page, whilstIncludeTitleis True Title,Author,Subject,Keywords,PDFVersion(default pdf17),PDFACompliance,PDFXComplianceandCompressionare passed through to the document
Dataset state
- The export calls
DisableControlswhilst it walks the dataset andEnableControlsafterwards, so bound controls do not repaint for each row - The current record is bookmarked first and restored at the end, when the export fails too
- A nil grid, an empty file name, a grid without a dataset, an inactive dataset or a grid without visible data columns raises an exception rather than returning False
Example
uses
dbGridHotPDFExport;
var
Options: TDBGridHotPDFExportOptions;
begin
Options:= DBGridHotPDFDefaultOptions;
Options.Title:= 'Customers';
Options.PageWidth:= 842; // A4 landscape
Options.PageHeight:= 595;
DBGridHotPDFExportToFile(DBGrid1, 'Customers.pdf', Options);
end;