TPDFlibPrinter
Printing, VCL, document creation
Description
Provides a component facade with the familiar BeginDoc, Canvas, NewPage, EndDoc, and Abort lifecycle while creating a PDF document instead of submitting a physical printer job
Declaration
Uses PDFlibPDFPrinter;
TPDFlibPrinter = Class(TComponent)Core methods
BeginDoc | Starts a new PDF document and exposes the first page through Canvas |
|---|---|
NewPage | Commits the current canvas as a PDF page and opens the next page canvas |
EndDoc | Commits the final page and writes FileName when a destination was assigned |
Abort | Discards the active job without writing its destination file and resets the component to an empty document |
SetPageSize | Sets portrait paper dimensions in PDF points before BeginDoc |
Properties
Canvas | The active VCL canvas between BeginDoc and EndDoc or Abort |
|---|---|
FileName | Optional PDF output path; an empty value retains the result only in LibraryInstance |
Title | Document title applied when the job begins |
DPI | Canvas coordinate resolution from 24 through 2400, defaulting to 96 |
CanvasOptions | Canvas import mode from -1 through 4, defaulting to vector mode 2 |
Orientation | poPortrait or poLandscape; landscape swaps the configured paper dimensions |
PaperWidth, PaperHeight | Portrait paper dimensions from 1 through 14400 PDF points |
PageWidth, PageHeight | Read-only active dimensions in canvas pixels after DPI and orientation conversion |
PageWidthPoints, PageHeightPoints | Read-only active dimensions in PDF points |
PageNumber | One-based current page during a job and zero while idle |
Printing, Aborted | Read-only lifecycle state |
LibraryInstance | The owned TPDFlib instance for inspecting or further processing the completed PDF |
LastErrorCode | The underlying library error code from the most recent PDF operation |
Example
Printer := TPDFlibPrinter.Create(nil);
try
Printer.FileName := 'report.pdf';
Printer.BeginDoc;
Printer.Canvas.TextOut(72, 72, 'First page');
Printer.NewPage;
Printer.Canvas.TextOut(72, 72, 'Second page');
Printer.EndDoc;
finally
Printer.Free;
end;Remarks
Configuration properties cannot change during an active document and lifecycle misuse raises EPDFlibPrinter
The component owns its library and canvas, creates an independent document for each job, preserves a completed document for further API operations, and never opens a print dialog or accesses the operating-system spooler
Use try/except around a job and call Abort only while the job remains active; failed internal conversion operations terminate the job and set Aborted