TPDFlib

Core object, document creation, document management

Description

TPDFlib (unit Lib\PDFlibrary.pas) is the central class of PDF Library for Delphi. A single instance hosts one or more PDF documents at the same time: NewDocument starts an empty document, LoadFromFile loads an existing one, SelectDocument switches the active document and DocumentCount reports how many are open. All drawing, text, form, annotation, security, signature, extraction, rendering, printing and validation calls operate on the currently selected document

The unit PDFlibrary is the umbrella unit: adding it to your uses clause pulls in the whole public surface, so most programs only ever need Uses PDFlibrary;

Syntax

Delphi

Uses PDFlibrary;

Var
  PDF: TPDFlib;
Begin
  PDF:= TPDFlib.Create;
  Try
    ...
  Finally
    PDF.Free;
  End;
End;

Key members

Create / DestroyLifecycle of the instance; freeing it closes every open document
NewDocumentStarts a new, empty PDF document and selects it
LoadFromFileLoads an existing PDF from disk (optionally with a password) and selects it
SelectDocumentMakes another open document the active one
DocumentCountNumber of documents currently open in the instance
SaveToFileWrites the active document to disk (incremental updates keep earlier signatures intact)
LastErrorCodeNumeric code of the most recent error; 0 when the last call succeeded
Abort / AbortedCancels a long-running operation cooperatively and reports the cancellation state
OnProgress / OnOperationProgressCoarse and fine-grained progress callbacks for long operations
OnPasswordAsks the host for a password when an encrypted document needs one
LoggerOptional TPDFlibLogger instance receiving structured log records
MailProviderOptional IPDFlibMailProvider used by the mail functions

Remarks

The reference pages in this documentation describe the members one by one, grouped by task: document management, page layout, vector graphics, fonts and text (including HTML stories and text flow), images, forms and JavaScript, annotations and links, outlines and destinations, security and digital signatures, tagged PDF, PDF/A and PDF/UA conformance, content extraction and direct access, rendering (SelectRenderer chooses GDI+, Cairo or PDFium), printing, preflight reports and viewer integration through TPDFlibViewer

Most members exist in three parallel flavors: as TPDFlib methods taking WideString, as DLL entry points with DL prefixes (plus A-suffixed ANSI variants for narrow-string callers, see SetAnsiMode) and as ActiveX/COM methods on the PDFlib library automation object. The per-member pages show the Delphi and DLL syntax side by side

Example

// Create a document, draw one line of text and save it
Uses PDFlibrary;

Procedure Demo;
Var
  PDF: TPDFlib;
Begin
  PDF:= TPDFlib.Create;
  Try
    PDF.NewDocument;
    PDF.AddStandardFont('Helvetica');
    PDF.PrintText(50, 750, 'Hello from PDF Library for Delphi');
    PDF.SaveToFile('hello.pdf');
  Finally
    PDF.Free;
  End;
End;

See also

DocumentationHome, GettingStarted, NewDocument, LoadFromFile, SelectDocument, DocumentCount, LastErrorCode, SelectRenderer, TPDFlibViewer, TPDFlibLogger