Table of Contents

Getting started with TMS FNC PDF Library

Prerequisites

  • TMS FNC Core installed and the runtime package added to the project.
  • The matching unit in your uses clause: FMX.TMSFNCPDFLib, VCL.TMSFNCPDFLib, or WEBLib.TMSFNCPDFLib.

Generate a simple PDF

BeginDocument starts the document, NewPage adds a page, and all drawing goes through Graphics. EndDocument finishes it — writing to the file you named, or returning the bytes as a TMemoryStream when you started the document without a file name.

procedure TForm1.GenerateHelloWorld(const AFileName: string);
var
  p: TTMSFNCPDFLib;
begin
  p := TTMSFNCPDFLib.Create;
  try
    { Passing a file name writes the document straight to disk; pass an empty
      string to get the bytes back from EndDocument as a TMemoryStream. }
    p.BeginDocument(AFileName);
    try
      p.NewPage;
      p.Graphics.Font.Name := 'Segoe UI';
      p.Graphics.Font.Size := 14;
      p.Graphics.DrawText('Hello, TMS FNC PDF Library!', PointF(40, 40));
    finally
      p.EndDocument;
    end;
  finally
    p.Free;
  end;
end;

Drop on a form

  1. Drop TTMSFNCPDFLib from the TMS FNC UI palette page onto a form or data module.
  2. Call BeginDocument / NewPage / Graphics.DrawText / EndDocument in a button handler.

Edit an existing PDF

OpenDocument parses a PDF that already exists so you can restructure, stamp and read it back, and SaveDocument writes the result.

PDF.OpenDocument('invoice.pdf');
PDF.RotatePage(0, 90);
PDF.SaveDocument('invoice-rotated.pdf');
PDF.CloseDocument;

Export graphics canvas to PDF

procedure TForm1.ExportButtonClick(Sender: TObject);
begin
  { The export object and its rectangle are passed to Save; TTMSFNCGraphicsPDFIO
    renders that object with the standard graphics drawing API. }
  GraphicsPDFIO1.Save('export.pdf', MyControl,
    RectF(0, 0, MyControl.Width, MyControl.Height));
end;
procedure TForm1.PrintButtonClick(Sender: TObject);
begin
  GraphicsPrintIO1.Print(MyControl,
    RectF(0, 0, MyControl.Width, MyControl.Height));
end;

Next steps