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
usesclause:FMX.TMSFNCPDFLib,VCL.TMSFNCPDFLib, orWEBLib.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;
void __fastcall TForm1::GenerateHelloWorld(const String AFileName)
{
TTMSFNCPDFLib *p = new TTMSFNCPDFLib();
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();
}
}
__finally
{
delete p;
}
}
Drop on a form
- Drop
TTMSFNCPDFLibfrom the TMS FNC UI palette page onto a form or data module. - Call
BeginDocument/NewPage/Graphics.DrawText/EndDocumentin a button handler.
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;
void __fastcall TForm1::ExportButtonClick(TObject *Sender)
{
// 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));
}
Print graphics output
procedure TForm1.PrintButtonClick(Sender: TObject);
begin
GraphicsPrintIO1.Print(MyControl,
RectF(0, 0, MyControl.Width, MyControl.Height));
end;
void __fastcall TForm1::PrintButtonClick(TObject *Sender)
{
GraphicsPrintIO1->Print(MyControl,
RectF(0, 0, MyControl->Width, MyControl->Height));
}
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.
function TForm1.CountPages(const AFileName: string): Integer;
var
p: TTMSFNCPDFLib;
begin
Result := 0;
p := TTMSFNCPDFLib.Create;
try
p.OpenDocument(AFileName);
try
if p.IsDocumentOpened then
Result := p.GetPageCount;
finally
p.CloseDocument;
end;
finally
p.Free;
end;
end;
int __fastcall TForm1::CountPages(const String AFileName)
{
int Result = 0;
TTMSFNCPDFLib *p = new TTMSFNCPDFLib();
try
{
p->OpenDocument(AFileName);
try
{
if (p->IsDocumentOpened())
Result = p->GetPageCount();
}
__finally
{
p->CloseDocument();
}
}
__finally
{
delete p;
}
return Result;
}
Next steps
- Guides — text, images, rich text, headers/footers, form fields, and print settings.
- Editing existing documents — open, inspect and save documents produced elsewhere.
- Rearranging pages — delete, move, duplicate, rotate, merge and extract pages.
- Page overlays and underlays — stamps, watermarks and footers on existing pages.
- API reference — PDF Lib — full class reference.