LLION/ PDF, print & document engineering

Generating PDFs with Delphi and Free Pascal

LLION Editorial · Updated

Delphi developers have generated PDFs for as long as the format has existed, mostly by one of two routes: a library that exposes a canvas, so that existing TCanvas drawing code produces pages instead of pixels, or a report engine whose PDF export is a checkbox. Both routes still work. What has changed is that the open-source options are now mature enough that a commercial SDK is a choice rather than a necessity.

## The options
LibraryApproachLicenceCompilersBest forAvoid when
SynPDF (Synopse)PDF canvas plus a VCL canvas via metafiles; PDF/A-1; Unicode with Uniscribe shaping; TrueType embedding; metafile (EMF) renderingTri-licence: MPL 1.1, GPL 2.0 or LGPL 2.1Delphi 6 and later, Win32 and Win64Reusing VCL drawing code; converting EMF report output; archival PDF/A-1FMX or Linux targets; FPC (use mORMot 2's mormot.ui.pdf.pas)
fcl-pdf (Free Pascal)Drawing API in the FCL: sections, pages, fonts, text, lines, imagesModified LGPL (FPC runtime licence)Free Pascal, Lazarus; cross-platformPure FPC projects on Linux, macOS or Windows with no VCLYou need rich text, tables or forms
llPDFLib (open source)Drawing API with a TPDFDocument component modelled on TPrinter; AcroForms, encryption, signatures, PDF/AMIT per the main repository README; a fork states AGPL-3.0 with a commercial licence and a producer-line requirementDelphi, C++Builder (Win32)Projects that need the Delphi-native feature set and can accept the licence ambiguityYou need an unambiguous licence or active maintenance
libHaru via Pascal bindingsC library called through a DLL or shared objectZLIB/LIBPNGDelphi and Free Pascal bindingsCross-platform drawing where a C dependency is acceptableDeployments that must be a single executable
FastReport VCL, ReportBuilder, QuickReport, LazReportReport engines with PDF exportCommercial (FastReport, ReportBuilder, QuickReport); LazReport is open sourceDelphi; LazReport for LazarusData-bound reports designed visuallyDocuments that are not reports
Gnostice PDFtoolkit VCL, wPDF, Foxit Quick PDF Library, TMS FNC PDFCommercial SDKs: creation, editing, forms, renderingCommercialDelphi; TMS FNC also FMX and cross-platformEditing existing files, viewers, FMX apps, vendor supportOpen-source projects

For the general choice between drawing, layout and HTML rendering, the developers hub has the decision table. Delphi tilts it: there is no mature layout engine in the QuestPDF or ReportLab sense, so paginated documents usually come from a report engine, and fixed layouts from a canvas library.

SynPDF: drawing with a VCL canvas#

SynPDF is the most capable open-source choice on Windows. TPdfDocument exposes a PDF-level canvas with text, path and image operators. TPdfDocumentGDI wraps it with a VCLCanvas property that is a regular TCanvas: everything you draw on it is recorded as a metafile and rendered into the PDF when the document is saved, which means code written for TPrinter.Canvas works unchanged.

HelloSynPdf.dpr (SynPDF, master branch; written against the source, not executed here)Object Pascal
program HelloSynPdf;

{$APPTYPE CONSOLE}

uses
  SysUtils, Graphics, SynPdf;

var
  Doc: TPdfDocumentGDI;
begin
  Doc := TPdfDocumentGDI.Create;
  try
    Doc.Info.Title := 'Delivery note';
    Doc.AddPage;                       // A4 portrait by default
    Doc.VCLCanvas.Font.Name := 'Arial';
    Doc.VCLCanvas.Font.Size := 18;
    Doc.VCLCanvas.TextOut(60, 60, 'Delivery note 2026-0142');
    Doc.VCLCanvas.Font.Size := 11;
    Doc.VCLCanvas.TextOut(60, 110, 'Shipped 29 October 2026');
    Doc.VCLCanvas.Pen.Width := 1;
    Doc.VCLCanvas.MoveTo(60, 130);
    Doc.VCLCanvas.LineTo(535, 130);
    if not Doc.SaveToFile('delivery-note.pdf') then
      Writeln('could not write file');
  finally
    Doc.Free;
  end;
end.

VCLCanvas coordinates are in the canvas's own units, scaled to the page when rendered. SaveToFile returns a boolean rather than raising. For a PDF/A-1 file, create the document with the APDFA1 parameter of TPdfDocument.Create, which forces font embedding and adds the required metadata. If you need the newer branch with Free Pascal support, the same engine lives on as mormot.ui.pdf.pas in mORMot 2.

Because the VCL route goes through a metafile, every TrueType glyph is embedded (subset by default) and Unicode text is shaped with Uniscribe, so right-to-left and complex scripts come out correctly on Windows. The fonts page explains what that embedding looks like inside the file.

fcl-pdf: the Free Pascal way#

Free Pascal ships a PDF writer in its component library. It is smaller than SynPDF, with no VCL canvas and no PDF/A, but it is pure Pascal, cross-platform, and needs nothing beyond the FPC installation. Documents are built from sections and pages; fonts are either the standard 14 by name or TrueType files loaded from disk or a stream.

hellofcl.lpr (fcl-pdf from FPC main; written against the example in the FPC source, not executed here)Object Pascal
program hellofcl;

{$mode objfpc}{$H+}

uses
  Classes, SysUtils, fppdf, fpparsettf, fpttf;

var
  D: TPDFDocument;
  S: TPDFSection;
  P: TPDFPage;
  FtTitle, FtBody: Integer;
  F: TFileStream;
begin
  D := TPDFDocument.Create(nil);
  try
    D.Infos.Title := 'Delivery note';
    D.Options := [poPageOriginAtTop];   // y grows downwards, as on screen
    D.StartDocument;
    S := D.Sections.AddSection;
    P := D.Pages.AddPage;
    P.PaperType := ptA4;
    P.UnitOfMeasure := uomMillimeters;
    S.AddPage(P);

    FtTitle := D.AddFont('Helvetica');                       // standard 14, not embedded
    FtBody := D.AddFont('fonts/DejaVuSans.ttf', 'DejaVuSans'); // TrueType, embedded

    P.SetFont(FtTitle, 18);
    P.SetColor(clBlack, False);
    P.WriteText(20, 25, 'Delivery note 2026-0142');
    P.SetFont(FtBody, 11);
    P.WriteText(20, 40, 'Shipped 29 October 2026');
    P.DrawLine(20, 46, 190, 46, 0.5);

    F := TFileStream.Create('delivery-note.pdf', fmCreate);
    try
      D.SaveToStream(F);
    finally
      F.Free;
    end;
  finally
    D.Free;
  end;
end.

The fpttf unit's font cache can find installed TrueType fonts by name on each platform; the example gives an explicit path to keep deployments predictable. Text with a standard-14 font is limited to the Latin-1 range, which is the same constraint every library has with those fonts.

llPDFLib: the component-style API#

llPDFLib is the open-sourced successor of the commercial library once sold on this domain; the history page covers its versions and where the code lives. Its TPDFDocument is a non-visual component with properties for file name, compression, security and document info, and a CurrentPage whose methods mirror a canvas. The demo projects in the repository are the best documentation.

HelloLL.dpr (llPDFLib, GitHub master; written against the repository demos, not executed here)Object Pascal
program HelloLL;

{$APPTYPE CONSOLE}

uses
  SysUtils, Graphics, llPDFDocument, llPDFTypes;

var
  PDF: TPDFDocument;
begin
  PDF := TPDFDocument.Create(nil);
  try
    PDF.FileName := 'delivery-note.pdf';
    PDF.AutoLaunch := False;
    PDF.DocumentInfo.Title := 'Delivery note';
    PDF.BeginDoc;
    with PDF.CurrentPage do
    begin
      SetActiveFont('Verdana', [fsBold], 18);
      TextOut(60, 60, 0, 'Delivery note 2026-0142');
      SetActiveFont('Verdana', [], 11);
      TextOut(60, 100, 0, 'Shipped 29 October 2026');
    end;
    PDF.EndDoc;
  finally
    PDF.Free;
  end;
end.

TextOut takes x, y, a rotation angle and the string; NewPage starts the next page. The exact unit names differ between the repository layout and the historical packages, so check the sources directory of the copy you build against.

The licence question deserves a plain statement. The main repository's README names the MIT licence. A widely linked fork carries an AGPL-3.0 licence file with an added producer-line requirement and a commercial licence offer, and credits Sybrex Systems. Which terms apply to which commit is not documented. If the licence matters to you, read the licence file in the exact revision you use, and treat the fork's terms as the stricter possibility.

Report engines#

If the document is a report, the shortest path is the report engine already in the project. FastReport VCL, ReportBuilder and QuickReport each export to PDF with embedded fonts and, in FastReport's case, PDF/A and tagged output; LazReport does the same for Lazarus. The trade-off is that the layout lives in a designer file rather than in code, which suits data-bound documents and suits nothing else. Historically, llPDFLib shipped export filters for QuickReport, FastReport and ReportBuilder so that those engines could emit PDF before they had their own exporters; that need has passed.

Commercial SDKs#

Gnostice PDFtoolkit VCL, wPDF from WPCubed, Foxit Quick PDF Library (formerly Debenu) and TMS FNC PDF cover the ground the open-source libraries leave open: editing and rendering existing files, form filling, viewers, and in TMS's case FireMonkey and cross-platform targets. They are the reasonable choice when the project needs vendor support or an FMX viewer. The table above lists them neutrally; nothing on this site is affiliated with any of them.

Traps specific to Object Pascal#

VCL versus FMX. SynPDF and llPDFLib are VCL and Win32/Win64 libraries. A FireMonkey application on macOS, iOS or Android needs fcl-pdf (via FPC), a commercial FNC library, or a server-side service. The HTML-to-PDF pipeline is a practical alternative for mobile clients: send HTML to a server that renders it.

Canvas scaling. A VCL canvas draws in pixels at the screen's logical DPI; SynPDF maps the metafile to the page, and llPDFLib's page has its own resolution property. Decide the mapping once, at the start of the document, and test on a printer, because a layout that looks right at 96 DPI can be off by a few percent at the printer's scale.

Metafiles and fonts. The EMF route embeds whatever font Windows resolved at draw time. If the font is not installed on the server that renders, GDI substitutes silently. Ship the fonts, install them on the server, and verify the embedded names in the output with the PDF inspector.

Unicode. Pre-Unicode Delphi (before 2009) needs libraries that accept wide strings explicitly; SynPDF handles this, llPDFLib's older code paths use AnsiString with charsets. On modern Delphi, string is UTF-16 and the libraries that embed TrueType fonts handle it, but the standard-14 fonts never will.

64-bit and Linux. Win64 is supported by SynPDF and by current commercial SDKs; check llPDFLib's package files for the target you need. Linux is FPC territory: fcl-pdf and mORMot 2 compile there; the VCL-based libraries do not.

Standards. If an archive or a print shop asks for PDF/A or PDF/X, choose a library that generates it directly (SynPDF for PDF/A-1, FastReport, the commercial SDKs) rather than converting afterwards; the standards page explains what each profile demands.

Sources