Getting Started

Installation, Delphi setup, First program

Description

PDF Library for Delphi is a Delphi PDF library. It is used from code by adding the library unit to your project and creating a TPDFlib instance when you need to build or modify a PDF document

Path Setting

Tell Delphi where to find the PDF Library for Delphi source files or compiled DCU files. You can set the global Library Path once, or set the Search Path for each project that uses the library.

To set the global Library Path, use this Delphi menu path:

Tools -> Options -> Language -> Delphi -> Library -> Library path

For older Delphi releases this setting may appear under:

Tools -> Environment Options -> Library -> Library path

Add the installed source path or the matching compiled binary path. Examples:

%UserProfile%\Documents\losLab\PDFlibPas\Lib
%UserProfile%\Documents\losLab\PDFlibPas\Lib\37.0\Win32\Release
%UserProfile%\Documents\losLab\PDFlibPas\Lib\37.0\Win64\Release

The first path is the default source edition path. The versioned paths are examples for RAD Studio 13 Florence compiled DCUs. Use the BDS-version folder that matches your installed Delphi or C++Builder version.

To set only the current project's Search Path, use:

Project -> Options -> Building -> Delphi Compiler -> Search path

For older Delphi releases this setting may appear under:

Project -> Options -> Directories/Conditionals -> Search path

Free Pascal and Lazarus on Windows

Both i386-win32 and x86_64-win64 are supported, including a Win32 compiler installation with a Win64 cross compiler; the library builds with FPC 3.2.2 and 3.3.1, while winarm64 requires FPC 3.3.1

The binary-only TRIAL SDK needs the FPC producer version recorded in its build stamp and a compiler able to read the supplied PPU files; installation and Trial demo builds check the SDK actually present, skip incompatible candidates on the PATH, and refuse an explicitly selected compiler that is incompatible

build-Lazarus-Lib.cmd win32
build-Lazarus-Tests.cmd win32
build-Lazarus-Demo.cmd win32
build-Lazarus-Lib.cmd win64

Use debug for a debug build and norun to build the console tests without running them; pass fpc=3.2.2 to pick a versioned installation such as an fpcupdeluxe side-by-side setup, or set FPC to the full path of fpc.exe when using a custom compiler installation

Compiled units are written to Lib\FPC\i386-win32 or Lib\FPC\x86_64-win64; add the matching directory and Lib\FPC\compat to the project's unit search path, use Delphi syntax mode, and keep the bundled Lib\thirdparty objects available to the linker; the Lazarus runtime package is Lib\FPC\PDFlibPasLaz.lpk

Test executables use Tests\Lazarus\bin\<target> and demo executables use each demo's bin\<target> directory; Win32 AES and JPEG 2000 use the supplied static COFF objects in Lib\thirdparty\Win32f; no codec DLL is required; Win32 uses the built-in Pascal JBIG2 encoder, including when the external encoder option is requested; the external PDFlibJBIG2EncC backend is available on Win64

Trial installations include precompiled units; run build-Lazarus-Demo-TRIAL.cmd win32 or select win64 to build the demos with the matching compiler version and target; when preparing trial binaries from the source tree, build the units first with build-Lazarus-Lib-TRIAL.cmd win32 or win64

Binary-only DCU-STD, DCU-SME, and DCU-ENT installations automatically rewrite Lib\FPC\PDFlibPasLaz*.lpk on post-install to link PDFlibPasBinaryUnits.pas together with the precompiled Lib\FPC\<target> units, allowing Lazarus projects to compile without shipping full library .pas sources

Class and Unit Name

The main library unit is PDFlibrary.pas, or PDFlibrary.dcu in a binary package. The core class for the Single (Full) edition is TPDFlib; for Small Business edition features create TPDFlibSmallBusiness (unit PDFlibSmallBusiness, Lazarus package PDFlibPasLazSmallBusiness.lpk), and for Enterprise edition features create TPDFlibEnterprise (unit PDFlibEnterprise, Lazarus package PDFlibPasLazEnterprise.lpk) — see Edition comparison

Declare the Class

PDF Library for Delphi is a Delphi library, not a VCL component. It is not installed onto the IDE component palette. Add PDFlibrary (or PDFlibSmallBusiness / PDFlibEnterprise for edition-gated workflows) to the unit's uses clause, declare a variable of type TPDFlib (or TPDFlibSmallBusiness / TPDFlibEnterprise), and call the Create constructor. When you are finished, call Free, normally inside a try..finally block

First PDF Library Program

Start a new VCL Forms application and add a TButton to the form. Add the PDF Library for Delphi unit to the form unit:

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics,
  Controls, Forms, Dialogs, PDFlibrary;

Double-click the button and add this event handler:

procedure TForm1.Button1Click(Sender: TObject);
var
  PDFlib: TPDFlib;
begin
  PDFlib := TPDFlib.Create;
  try
    PDFlib.DrawText(100, 500, 'Hello from Delphi');
    PDFlib.SaveToFile('.\HelloFromDelphi.pdf');
  finally
    PDFlib.Free;
  end;
end;

Complete Workflows

After the first PDF, explore the bundled Demo/Delphi, Demo/C++Builder, or Demo/Lazarus portfolio: Showcase and 9 core domain labs belong to the Single edition (16 core demos total), while SmallBusinessLab (Small Business edition) and EnterpriseLab (Enterprise edition) cover higher-edition workflows

Run DocumentLab --scenario DocumentInspectionWorkbench for page inventories and diagnostic reports, or supply your own PDF using the scenario's documented command-line arguments

Run ContentLab --scenario WorkflowGallery for a document delivery workflow with tables, annotations, a handover checklist, HTTP output and saved-file verification

Run SmallBusinessLab (Small Business edition) for document comparison and visual difference review PDFs (CompareWith, SaveVisualComparisonPDF), revision history and post-signature modification analysis (GetDocumentRevisionCount, AnalyzeModifications), electronic invoice business-rule validation (ValidateInvoiceBusinessRules), Bates numbering (AddBatesNumbering), PDF/VCR variable-content merging (ExecuteVCRDataMerge), optional content layer flattening (FlattenOptionalContent), batch conversion presets (ConvertFilesBatch) and professional barcodes (DrawRMQRCode, DrawGS1DataBarExpanded, DrawMaxiCode), or use the WorkflowCLI visual, batch and cancel-batch commands (Small Business edition)

Run EnterpriseLab (Enterprise edition) for PDF/A conversion (ConvertToPDFA), PDF/A, PDF/UA-1 and Arlington compliance preflight with structured reports (CheckFileCompliance, CheckFilePDFUACompliance, ValidateArlingtonSyntax, CreatePreflightReport), secure redaction (ApplyRedactions), public-key certificate encryption (EncryptPublicKey), PAdES B-LT/B-LTA long-term validation and OCSP/CRL revocation checking (ApplyPAdESLongTermValidation, ApplyPAdESLongTermArchiveValidation, TPDFlibSignatureVerifier), PKCS#11 hardware tokens (TPDFlibPKCS11Client), CSC cloud signing (TPDFlibCSCClient), EU Trusted Lists (TPDFlibEUTSLTrustSource) and signed audit evidence envelopes (CreateAuditEvidence, SignAuditEvidence, VerifyAuditEvidenceEnvelope), or use the WorkflowCLI audit, sign and verify commands (Enterprise edition)

DLL users can start with Demo/CSharp/DLL/DocWorkflow or Demo/VB.NET/DLL/DocWorkflow for report generation, extraction, page composition, and binary memory transfer, or Demo/VC++/DLL/LinkDemo for verified links and navigation. The C#, Visual Basic .NET, and Visual C++ WorkflowLab examples add twenty-four self-checking scenarios, including paged HTML, transactional text editing, JSON/CSV document inspection, navigation aids, page imposition, Fast Web View optimisation, optional-content layer flattening, vector graphics checked by rendering, review annotations, interactive form controls, barcode round trips, font embedding, image masks, SVG import and export, and document actions. For a tool that works on your own files, the PolicyAudit examples in the same three languages audit a PDF or a whole directory against a declared policy, report stable policy failure codes in JSON, CSV, and HTML, and return an exit code for automation; the PDF/A and PDF/UA preflight switches need the Enterprise edition DLL

When the DLL module is selected during installation, open Demo/DLL.en-us.html for the DLL workflow catalogue and architecture-specific build instructions. The Readme.en-us.html files in Demo/CSharp/DLL, Demo/VB.NET/DLL, and Demo/VC++/DLL list the examples for each language, including the older Visual Studio projects

For a current .NET SDK console host, use Demo/CSharp/DLL/RenderJob to bind a native DLL with SafeHandle, render a PDF page to PNG, and handle pause, resume, cancellation and failure

When the ActiveX module is selected during installation, look for Readme.en-us.html in Demo/CSharp/ActiveX, Demo/VB.NET/ActiveX, or Demo/VC++/ActiveX for the COM automation guides and links to the Visual Studio projects. The desktop ExtractText and ImageToPDF examples are available in all three languages, and the MultiDemo desktop tour is also available in all three. The headless ComWorkflow examples show how to keep an editable approval packet and deliver a flattened PDF with a verified binary attachment

More Information

Use this HTML reference for detailed API documentation. You can search the navigation pane by function name, category, or topic keyword

For product news and additional information, visit the PDF Library for Delphi product page