TDBGrid export support
The dbGridHotPDFExport add-on unit (Lib\addons\DBGrid) writes the visible columns and all rows of a TDBGrid dataset to a PDF table. It creates, fills and saves its own THotPDF document, so the grid is the only input it needs
Entry points
DBGridHotPDFExportToFile(AGrid, AOutputFileName[, AOptions])writes the PDF to a fileDBGridHotPDFExportToStream(AGrid, AOutputStream[, AOptions])writes it to a stream, through a temporary file in%TEMP%DBGridHotPDFDefaultOptionsreturns aTDBGridHotPDFExportOptionsrecord with 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 as a component on the HotPDF palette page (registered bydbGridHotPDFDesign): setGridandOutputFileName, then callExportToFileorExportToStream. Each option field is a published property;ResetOptionsrestores the defaults
What is exported
- Visible grid columns with a field, in grid order, with their title captions, or the visible fields of the dataset 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; a cell text that does not fit is cut and ends in... - All text uses
FontName, which must have 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, whileIncludeTitleis True Title,Author,Subject,Keywords,PDFVersion(default pdf17),PDFACompliance,PDFXComplianceandCompressionare passed to the document
Dataset state
- The export calls
DisableControlswhile it walks the dataset andEnableControlsafterwards, so bound controls do not repaint for each row - The current record is saved as a bookmark first and restored at the end, also when the export fails
- 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 instead of 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;