Developer Tools
|
Office Productivity Applications
|
Platform-Agnostic APIs
|
||||||||||||||||||||||||||







Home | Online Demos | Downloads | Buy Now | Support | About Us | News | Working Together | Contact Us
If you have used word-processing software such as Microsoft Word, you may be familiar with the concept of "auto text." PDFtoolkit brings the same functionality to PDF by supporting placeholders in PDF page text-outs. You can use placeholders with TgtTextWatermarkTemplate class and the TgtDFDocument.TextOut method. PDFtoolkit comes with the following built-in placeholders.
| Placeholder | Substituted By |
|---|---|
| PageNo | Number of current page |
| TotPage | Total number of pages |
| ShortDate | Date in short format |
| ShortTime | Time in short format |
| LongDate | Date in long format |
| LongTime | Date in long format |
| Author | Document author property (See TgtPDFDocument.DocInfo) |
| Creator | Document creator property (See TgtPDFDocument.DocInfo) |
| Subject | Document subject property (See TgtPDFDocument.DocInfo) |
| Title | Document title property (See TgtPDFDocument.DocInfo) |
PDFtoolkit also supports custom or user-defined placeholders. Your application can provide values for custom placeholders by handling the TgtPDFDocument.OnCalcVariables event.
Both built-in and custom placeholders need to be delimited by <% and %>. When the output document is being paged, the placeholders will be replace with their values available at run time. Here is an example.
{
This code example illustrates how to write text
watermarks to a document. It also illustrates the
use of autotext placeholders.
}
program Examples_Autotext;
{$APPTYPE CONSOLE}
uses
SysUtils,
gtPDFDoc, gtCstPDFDoc;
var
gtPDFDocument1: TgtPDFDocument;
gtTextWatermarkTemplate1: TgtTextWatermarkTemplate;
begin
// Create a document object
gtPDFDocument1 := TgtPDFDocument.Create(Nil);
gtTextWatermarkTemplate1 := TgtTextWatermarkTemplate.Create();
try
// Load input document
gtPDFDocument1.LoadFromFile('input_doc.pdf');
// Check if document has loaded successfully
if gtPDFDocument1.IsLoaded then
begin
// Set watermark properties
With gtTextWatermarkTemplate1 do
begin
Font.Name := 'Courier New';
Font.Size := 8;
Text := 'Autotext example [PageNo - <%PageNo%>, TotPage - <%TotPage%>, '
+ 'ShortDate - <%ShortDate%>, Author - <%Author%>]';
Overlay := false; // Underlay
OpacityStroke := 100; // Full opaqueness
HorizPos := hpCenter; // Relative positioning
VertPos := vpCustom; // Absolute positioning
Y := 10; // Absolute vertical position
end;
// Apply the watermark on all pages
gtPDFDocument1.InsertWatermark(gtTextWatermarkTemplate1);
// Save modified document
gtPDFDocument1.SaveToFile('output_doc.pdf');
end
else
begin
// Output error message
Writeln('Sorry, I could not load input_doc.pdf.');
end;
except on Err:Exception do
begin
Writeln('Sorry, an exception was raised. ');
Writeln(Err.Classname + ':' + Err.Message);
end;
end;
// Free resources
gtPDFDocument1.Reset;
// Destroy PDF document object
FreeAndNil(gtPDFDocument1);
Writeln('Press Enter to exit.');
Readln;
end.
And, here is the output.

---o0O0o---
| Our .NET Developer Tools | |
|---|---|
Gnostice Document Studio .NETMulti-format document-processing component suite for .NET developers. |
PDFOne .NETA .NET PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, and bookmark PDF documents in .NET applications. |
| Our Delphi/C++Builder developer tools | |
|---|---|
Gnostice Document Studio DelphiMulti-format document-processing component suite for Delphi/C++Builder developers, covering both VCL and FireMonkey platforms. |
eDocEngine VCLA Delphi/C++Builder component suite for creating documents in over 20 formats and also export reports from popular Delphi reporting tools. |
PDFtoolkit VCLA Delphi/C++Builder component suite to edit, enhance, view, print, merge, split, encrypt, annotate, and bookmark PDF documents. |
|
| Our Java developer tools | |
|---|---|
Gnostice Document Studio JavaMulti-format document-processing component suite for Java developers. |
PDFOne (for Java)A Java PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, bookmark PDF documents in Java applications. |
| Our Platform-Agnostic Cloud and On-Premises APIs | |
|---|---|
StarDocsCloud-hosted and On-Premises REST-based document-processing and document-viewing APIs |
| Privacy | Legal | Feedback | Newsletter | Blog | Resellers | © 2002-2026 Gnostice Inc. All rights reserved. |