Gnostice 


Smart needs... Smarter solutions...
 

PDFtoolkit VCL

OEM Options

To send us your requirements, click here.




Home > Products > Software Developers > PDFtoolkit VCL > FAQs
 
      PDFtoolkit VCL - Merge, Split, Overlay, Stamp, View, Print PDF documents 
 
General

What is Gnostice PDFtoolkit?
Why do I need Gnostice PDFtoolkit?
Can I edit PDF documents using PDFtoolkit?
Who can use PDFtoolkit?
What are the minimum requirements for using PDFtoolkit?
Can I try PDFtoolkit before I buy?
What are the limitations of the trial edition?
Does Gnostice PDFtoolkit require Adobe® Acrobat™ to work?
Do I need to supply any additional files with my application for PDFtoolkit to work?
How do I buy Gnostice PDFtoolkit?
What versions of PDF documents does PDFtoolkit support?

Technical

Can I create PDF documents from scratch using PDFtoolkit?
Can I edit a PDF document using PDFtoolkit?
Can I manage encrypted PDF documents using PDFtoolkit?
What do I need to do for PDFtoolkit to show all messages in my language/How do I localize PDFtoolkit?
How do I Merge multiple PDF documents?
How do I Insert pages from one PDF document to another and specify where to insert the pages?
How do I Extract pages from an existing PDF document and create a new one?
How do I insert a Marking (Watermark/rubber Stamp) on every page of my PDF document?
Can I insert multiple or Composite Watermarks to my PDF document?
How do I insert a bitmap as Watermark?
How do I Set Values to form fields on a PDF form (Acroform) and permanently save the values?
How do I Extract Field Values from a filled PDF form?
How do I Extract Field Names from a PDF form?
How do I set my own Thumbnail for a specific page in the PDF document?
How do I Email a document after saving?
How do I insert a Bookmark or Outline item to my PDF document?
How do I load an existing bookmark into a TreeView Control?
How do I insert a new node after a currently selected node in a TreeView?
How do I delete an existing node in a TreeView?
How do I encrypt a PDF document using PDFtoolkit
Can I extract text from a PDF document? If yes, how do I accomplish it?
Can I convert PDF documents to various formats supported by eDocEngine using both PDFtoolkit and eDocEngine?
What is gdiplus.dll? Why is it required, where to find it and how to install/redistribute it?


General

What is Gnostice PDFtoolkit?
Gnostice PDFtoolkit is a powerful component set for Borland® Delphi™ and Borland® C++Builder™ developers to help manage PDF documents from within application programs. PDFtoolkit supports filling and reading of PDF forms, compressing, securing, appending and merging of multiple PDF documents, stamping, building Table of Contents, setting bookmarks, and many more functions that can be performed on PDF documents. PDFtoolkit operates on existing PDF documents and can even create new ones by extracting pages from existing documents. With the help of PDFtoolkit developers can program powerful PDF document management functions that can be performed from within the business applications they develop, making the applications more efficient and independent of other external software.

Why do I need Gnostice PDFtoolkit?
There are several reasons for using Gnostice PDFtoolkit. One scenario is when you need to acquire information from users through a PDF form based solution. You would use PDFtoolkit to fill form fields and read the filled forms to directly extract data into a database. Another scenario is when you need to process PDF documents from your application and perform tasks such as extracting pages, merging documents, encrypting documents and so on.

Can I edit PDF documents using PDFtoolkit?
You cannot edit the content of pages as you would in a word processor but you can insert, delete and extract pages, merge multiple documents, set watermarks and stamp documents.

Who can use PDFtoolkit?
If you are a software developer and you use Borland® Delphi™ or Borland® C++Builder™ to develop your software, you can use PDFtoolkit. PDFtoolkit can be embedded to enable your applications to manage and manipulate PDF documents for specific user needs.

What are the minimum requirements for using PDFtoolkit?
Please see the System Requirements for complete details.

Can I try PDFtoolkit before I buy?
YES. The FREE full-feature trial versions of PDFtoolkit are available on the Download page.

What are the limitations of the trial edition?
Trial versions have the following limitations:
• The trial version expires 30 days from date of install.
• Applications developed using the trial version will only work on the computer that has the trial version installed.
• Each page of the managed/viewed/printed document will contain a message stating the document was created using the trial version of Gnostice PDFtoolkit and the Gnostice web site address printed across the middle.
• Text extraction functions return text with some characters replaced by asterisk (*).

Does Gnostice PDFtoolkit require Adobe® Acrobat™ to work?
NO. PDFtoolkit is a 100% native, embeddable solution that does not require any external software or DLLs.

Do I need to supply any additional files with my application for PDFtoolkit to work?
No. However, your application's installer program (setup) should install a Windows file, gdiplus.dll, if the Windows operating system is older than Windows XP. Sometimes, gdiplus.dll may already be installed, in which case your installer program should not attempt to overwrite the existing dll, as this will run into conflict with an inherent Windows feature to protect system files from being overwritten.

Apart from this, you need to supply only your final compiled executable (EXE) application to your users. Further, the License restricts the distribution of certain files supplied with PDFtoolkit. Please check the License section for details.


How do I buy Gnostice PDFtoolkit?
You can buy PDFtoolkit online and get instant access to the registered version. There are several payment options available. Please check the Buy Now section for details.

What versions of PDF documents does PDFtoolkit support?
PDFtoolkit supports PDF version 1.2 (Acrobat 3) to version 1.6 (Acrobat 7).


Technical

Can I create PDF documents from scratch using PDFtoolkit?

No. PDFtoolkit can be used only for managing existing PDF documents. To create PDF files from scratch please take a look at Gnostice eDocEngine


Can I edit a PDF document using PDFtoolkit?

No. You cannot edit the content of pages as you would in a word processor but you can insert, delete and extract pages, merge multiple documents, set watermarks and stamp documents.


Can I manage encrypted PDF documents using PDFtoolkit?

Yes. PDFtoolkit can read and manage encrypted documents. An existing encrypted document's encryption setting can be altered, or even removed to have it decrypted. PDFtoolkit respects the access permissions set by the document author. If you provide the owner password, you can perform all supported operations. With the user password, you can perform the operations the author intended you to perform.


What do I need to do for PDFtoolkit to show all messages in my language/How do I localize PDFtoolkit?
To simplify localization of user messages, PDFtoolkit uses resourcestrings throughout, wherever strings need to be displayed, including captions of controls on the dialogs. All these resourcestrings are located in the unit gtPDFResStrs.pas, if you need to change them. For Registered versions only.


How do I Merge multiple PDF documents?
PDFtoolkit can merge multiple PDF documents into a singe document using 'MergeDocs' function. 

To merge the PDF documents:
1) Open Delphi/C++Builder application and add the PDFtoolkit component to the form. 
2) Then add a button to the form and change the button caption to 'Merge PDFs' 
3) Double click the button and get to the Button's click event in the code editor. 
4) Paste the Delphi/C++Builder code mentioned below in the button's click event. 

Source Code: This code merges 3 PDF files namely Doc1.pdf, Doc2.pdf and Doc3.pdf. These input files are accepting to a string list. Using 'MergeDocs' method merges the input files and saves them to output.pdf file using 'SaveToFile' method 

  Delphi:
    Var
      // Declare the string list to accept the input PDF files to be merged
      LFileNames: TStringList;
    begin
      LFileNames := TStringList.Create;
      // Add input PDF files to string list
      LFileNames.Add('Doc1.pdf');
      LFileNames.Add('Doc2.pdf');
      LFileNames.Add('Doc3.pdf');
      // Merge input PDF files
      gtPDFDocument1.MergeDocs(LFileNames);
      // Save merged file to Disk 
      gtPDFDocument1.SaveToFile('Output.pdf');
      // Free string list from memory 
      FreeAndNil(LFileNames);

    end;

  C++Builder:
    // Declare the string list to accept the input PDF files to be merged
    TStringList *LFileNames;
    // Provide filenames of documents in a string list.
    LFileNames = new TStringList();
    LFileNames->Add("Doc1.pdf");
    LFileNames->Add("Doc2.pdf");
    LFileNames->Add("Doc3.pdf");

    // Merge the documents.
    gtPDFDocument1->MergeDocs(LFileNames);

    // Save merged file to disk.
    gtPDFDocument1->SaveToFile("Output.pdf");

    // Free string list from memory
    Gtutils::FreeAndNil(LFileNames);

5) Run the application. Click on 'Merge PDF' button on the form. This creates the merged PDF file named 'Output.pdf'. View the file to see if all the input files are merged. 


How do I Insert pages from one PDF document to another and specify where to insert the pages?
Pages can be inserted from one PDF document into another using the 'InsertPagesFrom' function by providing the range of pages that needs to be inserted and also the location about from where these pages need to be inserted.

Create an appliaction to inserts pages as shown below:

  1) Open Delphi/C++Builder application and add the PDFtoolkit component to the form. 
  2) Then add a button to the form and change the button caption to 'Page Insertion'. 
  3) Double click the button and get to the Button's click event in the code editor. 
  4) Paste the Delphi/C++Builder code mentioned below in the button's click event. 

Source Code: For Page insertion you need two input files. Two file 'Input1.pdf' and 'Input2.pdf' are used in    this code where page 1 to 5 from 'input2.pdf' is inserted into input1.pdf and generate an 'output.pdf'. For inserting pages, the function 'InsertPagesFrom' of PDFtoolkit is used in the code.

  Delphi:
    begin
    // Load a PDF Document
    gtPDFDocument1.LoadFromFile('Input1.pdf');
    // Insert pages from another document into current document after page 1
    gtPDFDocument1.InsertPagesFrom('Input2.pdf', '1-5', 1);
    // Save the document to file.
    gtPDFDocument1.SaveToFile('Output.pdf');
  end;

  C++Builder:
    // Load a PDF Document
    gtPDFDocument1->LoadFromFile("Input.pdf");
    // Insert pages from another document into current document after page 1
    gtPDFDocument1->InsertPagesFrom("Output.pdf", "1-5", 1);
    // Save the document to file.
    gtPDFDocument1->SaveToFile("Output.pdf");

5) Run the application. Click on 'Page Insertion' button on the form. This page insertion can be viewed in 'Output.pdf'.


How do I Extract pages from an existing PDF document and create a new one?
You can extract pages, text and Images from a PDF document and save them to a separate file. This tutorial guides you to extract pages, text and images from the PDF document. Follow these links to explore each one of them.
1. Extract Pages
2. ExtractText 
3. Extract Text Formatted
4. Extract Images 

Extract Pages

To extract pages using PDFtoolkit:

1. Drop PDFtoolkit component (TgtPDFDocument) to the form and load PDF document using the 'LoadFromFile' method.
2. Using 'ExtractPagesTo' function, select the range of pages to be extacted form the loaded PDF document. Also provide the output PDF file name to store the extracted pages. 

Here is an application to extract pages from PDF documents.
1. Open Delphi/C++Builder application and add the PDFtoolkit component to the form. 
2. Add a button to the form and change the button caption to 'Extract Pages' 
3. Double click the button and get to the Button's click event in the code editor. 
4. Paste the Delphi/C++Builder code mentioned below in the button's click event. The following code creates Output.pdf by extracting pages 1 to 10 from 'Input.pdf'. Note: The 'Input.pdf' must contain 10 pages.

  Delphi:
    begin

      gtPDFDocument1.LoadFromFile('Input.pdf');
      gtPDFDocument1.ExtractPagesTo('Output.pdf', '1-10');
    end;

  C++Builder:
    gtPDFDocument1->LoadFromFile("Input.pdf");
    gtPDFDocument1->ExtractPagesTo("Output.pdf", "1-10") 

5. Run the application. Click on 'Extract Pages' button on the form. This creates the merged PDF file named 'Output.pdf'. View the file to see if all the input files are merged. 


Extract Text 

PDFtoolkit provides "ExtractText" function to extract text from a page in the currently loaded document.
To extract text:
1. Drop PDFtoolkit component (TgtPDFDocument) to the form and load PDF document using the 'LoadFromFile' method.
2. Using 'ExtractText' function, select the text from the loaded PDF document and store it in a string list.
3. Using 'SaveToFile' method store the contents to a text file. 

Here is an application to extract text from a PDF document.

1. Open Delphi/C++Builder application and add the PDFtoolkit component to the form. 
2. Then add a button to the form and change the button caption to 'Extract Text' 
3. Double click the button and get to the Button's click event in the code editor. 
4. Paste the Delphi/C++Builder code mentioned below in the button's click event. 

Source Code: The following example creates output.txt by extracting text from Page1 of 'Input.pdf'.

  Delphi:
    var
      list: TStringList;
    begin
      gtPDFDocument1.LoadFromFile('Input.pdf');
      list := gtPDFDocument1.ExtractText('1-3');
      list.SaveToFile('Output.txt');
    end;

  C++Builder:
    TStringList* list;
    gtPDFDocument1->LoadFromFile("Input.pdf");
    list = gtPDFDocument1->ExtractText('1-3');
    list->SaveToFile("Output.txt"); 

5. Run the application. Click on 'Extract Text' button on the form. This creates the merged PDF file named 'Output.pdf'. View the file to see if all the input files are merged. 


Extract Text Formatted (ProPlus Edition only)
PDFtoolkit provides "ExtractTextFormatted" function to extract text from a page in the currently loaded document.
To extract text:
1. Drop PDFtoolkit component (TgtPDFDocument) to the form and load PDF document using the 'LoadFromFile' method.
2. Using 'ExtractTextFormatted' function, select the text from the loaded PDF document and store it in a string list.
3. Using 'SaveToFile' method store the contents to a text file. 

Here is an application to extract text from a PDF document.

1. Open Delphi/C++Builder application and add the PDFtoolkit component to the form. 
2. Then add a button to the form and change the button caption to 'Extract Text Formatted' 
3. Double click the button and get to the Button's click event in the code editor. 
4. Paste the Delphi/C++Builder code mentioned below in the button's click event. 

  Source Code: The following example creates output.txt by extracting text from Page1 of 'Input.pdf'.

  Delphi:
    var
      list: TStringList;
    begin
      gtPDFDocument1.LoadFromFile('Input.pdf');
      list := gtPDFDocument1.ExtractTextFormatted(1);
      list.SaveToFile('Output.txt');
    end;

  C++Builder:
    TStringList* list;
    gtPDFDocument1->LoadFromFile("Input.pdf");
    list = gtPDFDocument1->ExtractTextFormatted(1);
    list->SaveToFile("Output.txt");

5. Run the application. Click on 'Extract Text Formatted' button on the form. This creates the merged PDF file named '
Output.pdf'. View the file to see if all the input files are merged. 

Extract Images

To extract Images follow these steps:
1. Drop PDFtoolkit component (TgtPDFDocument) to the form and load PDF document using the      'LoadFromFile' method.

gtPDFDocument1.LoadFromFile('Input.pdf');
2. Create instance of TgtPDFPageElementList 
LImageList : TgtPDFPageElementList;

3. Using 'GetPageElements' method, extract images present in the page form the loaded PDF document. To extract images need to set the second argument to [etImage] 

LImageList := PDFDoc.GetPageElements(1
 
,[etImage],muPixels);

4. To store the extracted graphics elements from the list. need to type cast each list element to TgtPDFImageElement
LGraphics := TgtPDFImageElement(LImageList.Items[LI]);

5. Check if the images are of BMP(IsBMPImage) or JPEG(IsJPEGImage) format and store them appropriately

  if LGraphics.IsBMPImage then
    LGraphics.SaveToFile(IntToStr(LI)+'.bmp')
  else
    LGraphics.SaveToFile(IntToStr(LI)+'.jpg');

Follow these steps to create an application to extract Images. 

1. Open Delphi application and add the PDFtoolkit component to the form. 
2. Then add a button to the form and change the button caption to 'Extract Images' 
3. Double click the button and get to the Button's click event in the code editor. 
4. Paste the below mentioned code in the button's click event. 

The following code creates images extracted from page1 of 'input.pdf' and save to the respective image format.

  Delphi:

    var
    LImageList : TgtPDFPageElementList;
    LGraphics: TgtPDFImageElement;
    LI : Integer;
    begin
      PDFDoc.LoadFromFile('Input.pdf');
      LImageList := PDFDoc.GetPageElements(1,[etImage],muPixels);
      LI := 0;
      While LI < LImageList.Count do
      begin
        LGraphics := TgtPDFImageElement(LImageList.Items[LI]);
        if LGraphics.IsBMPImage then
          LGraphics.SaveToFile(IntToStr(LI)+'.bmp')
        else
          LGraphics.SaveToFile(IntToStr(LI)+'.jpg');
      Inc(LI,1);
    end;
  end;

  C++Builder:
    TgtPDFPageElementList *ImageList;
    TgtPDFImageElement *LGraphic;
    int LI;

    gtPDFDocument1->LoadFromFile("Input.pdf");

    ImageList = gtPDFDocument1->GetPageElements(2, TgtElementTypes() << etImage, muPixels);

    for (LI = 0; LI < ImageList->Count; LI++)
    {
      LGraphic = (TgtPDFImageElement*)ImageList->Items[LI];
      if (LGraphic->IsBMPImage)
        LGraphic->SaveToFile(IntToStr(LI) + ".bmp");
      else if (LGraphic->IsJPEGImage)
      LGraphic->SaveToFile(IntToStr(LI) + ".jpeg");
}

5. Run the application. Click on 'Extract Images' button on the form. This extracts the image from page 1 of the loaded document.


How do I insert a Marking (Watermark/rubber Stamp) on every page of my PDF document?
Markings can be of type Text, Image or Composite. The text marking can be inserted by calling the InsertWatermark function with an object of
TgtTextWatermarkTemplate type as shown below. Similarly, an image marking can be inserted by creating an object of gtImageWatermarkTemplate, and providing that to the InsertWatermark method.
Stamping/Markings can be of type Text, Image or Composite. Click these links for watermark examples.

1. Text Watermark 
2. Image Watermark
3. Composite Watermark
4. Insert predefined variables
5. Insert user-defined variables

Text Watermark

To create an application to insert text watermark:

1. Open Delphi/C++Builder application and drop PDFtoolkit component (TgtPDFDocument) to the form to load PDF document using the 'LoadFromFile' method.
2. Then add a button to the form and change the button caption to 'Create Watermark' 
3. Double click the button and get to the Button's click event in the code editor. 
4. Paste the Delphi/C++Builder code mentioned below in the button's click event. 

Source Code
To create watermark declare 'TgtTextWatermarkTemplate' and set properties of text, angle, fonts etc. Once all the properties are set, use 'InsertWatermark' function to insert watermark to PDF document.

  Delphi:
  var
    Watermark: TgtTextWatermarkTemplate;
  begin
    // Create and set watermark properties
    PDFDoc.MeasurementUnit := muPixels;
    Watermark := TgtTextWatermarkTemplate.Create;
  with Watermark do
  begin
    Text := 'Gnostice PDFtoolkit';
    Angle := 45;
    Font.Name := 'Times New Roman';
    Font.Size := 40;
    Font.Style := [fsBold];
    RenderMode := rmStroke;
    StrokeColor := clMaroon;
    Overlay := True;
    HorizPos := hpCenter;
    VertPos := vpMiddle;
    // set this property to 'wmVertical' for Vertical text display
    WritingMode := wmVertical;
  end;
    // Insert the watermark
    PDFDoc.InsertWatermark(Watermark);
    Watermark.Free;
  end;

  C++Builder:
      TgtTextWatermarkTemplate *Watermark;
    // Create and set watermark properties
    gtPDFDocument1->MeasurementUnit = muPixels;
    Watermark = new TgtTextWatermarkTemplate();
    Watermark->Text = "Gnostice PDFtoolkit";
    Watermark->Angle = 45;
    Watermark->Font->Name = "Times New Roman";
    Watermark->Font->Size = 40;
    Watermark->Font->Style = TFontStyles() << fsBold;
    Watermark->RenderMode = rmStroke;

    Watermark->StrokeColor = clMaroon;
 
    Watermark->Overlay = True;
    Watermark->HorizPos = hpCenter;
    Watermark->VertPos = vpMiddle;
     // set this property to 'wmVertical' for Vertical text display
    Watermark->WritingMode = wmVertical;
    // Insert the watermark
    gtPDFDocument1->InsertWatermark(Watermark);

    Watermark->Free();

5. Run the application. Click on 'Create Watermark' button on the form. View Watermark in the output.pdf file.

Image Watermark

In this example we will insert a bitmap image as watermark to a PDF document.

1. Open Delphi/C++Builder application and drop PDFtoolkit component (TgtPDFDocument) to the form to load PDF document using the 'LoadFromFile' method.
2. Then add a button to the form and change the button caption to 'Insert Bitmap Watermark' 
3. Double click the button and get to the Button's click event in the code editor. 
4. Paste the Delphi/C++Builder code mentioned below in the button's click event. 

  Delphi:
    var
      Watermark: TgtImageWatermarkTemplate;
       Bitmap: TBitmap;
     begin
      // Load image into bitmap
      Bitmap := TBitmap.Create;
      Bitmap.LoadFromFile('BitmapFile.bmp');
      // Create and set watermark properties
      Watermark := TgtImageWatermarkTemplate.Create;
      With Watermark do
      begin
       
Image := Bitmap;
        Overlay := True;
        HorizPos := hpCenter;
        VertPos := vpMiddle;
      end;
      // Insert the watermark (assuming that gtPDFDocument1 is already loaded.)
      gtPDFDocument1.InsertWatermark(Watermark);
      FreeAndNil(Bitmap);
      FreeAndNil(Watermark);
      end; 

  C++Builder:
    TgtImageWatermarkTemplate *Watermark;
    Graphics::TBitmap *Bitmap;
    // Load image into bitmap
    Bitmap = new Graphics::TBitmap();
    Bitmap->LoadFromFile("BitmapFile.bmp");
    // Create and set watermark properties
    Watermark = new TgtImageWatermarkTemplate();
    Watermark->Image = Bitmap;
    Watermark->Overlay = True;
    Watermark->HorizPos = hpCenter;
    Watermark->VertPos = vpMiddle;
    // Insert the watermark (assuming that gtPDFDocument1 is already loaded.)
    gtPDFDocument1->InsertWatermark(Watermark);
    Gtutils::FreeAndNil(Bitmap);
    Gtutils::FreeAndNil(Watermark);
5. Run the application. Click on 'Insert Bitmap Watermark' button on the form. Bitmap gets inserted to the PDF document.


Composite Watermark

This tutorial creates a composite watermark using text watermark and image watermark.

Follow the steps to create an application. 

1. Open Delphi/C++Builder application and drop PDFtoolkit component (TgtPDFDocument) to the form to load PDF document using the 'LoadFromFile' method. 
2. Then add a button to the form and change the button caption to 'Insert Composite Watermark' 
3. Double click the button and get to the Button's click event in the code editor. 
4. Paste the Delphi/C++Builder code mentioned below in the button's click event. 

  Delphi:
    var
      LWatermark: TgtCompositeWatermarkTemplate;
    begin

      LWatermark := TgtCompositeWatermarkTemplate.Create;
      LWatermark.AddWatermark(TextWatermark);
      LWatermark.AddWatermark(ImageWatermark);
      PDFDoc.InsertWatemark(LWatermark);
      FreeAndNil(LWatermark);
    end;

  C++Builder:
    TgtCompositeWatermarkTemplate *LWatermark;
    LWatermark = new TgtCompositeWatermarkTemplate();
    LWatermark->AddWatermark(TextWatermark);
    LWatermark->AddWatermark(ImageWatermark);
    gtPDFDocument1->InsertWatemark(LWatermark);
    FreeAndNil(LWatermark); 
5. Run the application. Click 'Insert Composite Watermark' button on the form. This deletes the pages mentioned to be deleted and saves the file as output.pdf.


Insert predefined variables
This tutorial explains about inserting pre-defined variables (date, time, etc.) to the place holders created in the PDF document.

To insert predefined variables to the PDF document:
 
1. Open Delphi/C++Builder application and drop PDFtoolkit component (TgtPDFDocument) to the form to load PDF document using the 'LoadFromFile' method.
2. Create instance of 'TgtTextWatermarkTemplate' class and set their properties.
3. Create the place holders string and assign them to Text property of watermark. Create place holders for page number(
<%PageNo%>), total number of pages(<%totPage%>) and date(<%Longdate%>).

4. Using InsertWatermark method provide the watermark object created along with the page numbers for creating the predefined variables on these pages of the output document.

Here is an application to insert predefined variables to a PDF document.

1. Open Delphi IDE.
2. Select 'PDFtoolkit' tab from the component palette and drag PDFtoolkit component to the Form.
3. Add a button to the form and change the caption property to 'Insert Predefined Variables'. 
4. Double click 'Insert Predefined Variables' button to open the code window. Paste the code for inserting text box in Button's onclick event.

  Delphi:
  var
    Watermark: TgtTextWatermarkTemplate;
  begin
    PDFDoc.LoadFromFile('Input.pdf');
    PDFDoc.MeasurementUnit := muPixels;
    // Create and set watermark properties
    Watermark := TgtTextWatermarkTemplate.Create;
  with Watermark do
  begin
    Text := 'Page <%PageNo%> of <%totPage%> , Date - <%Longdate%>';
    Font.Name := 'Times New Roman';
    Font.Size := 15;
    Font.Style := [fsBold];
    RenderMode := rmFill;
    Overlay := False;
    HorizPos := hpCenter;
    VertPos := vpCustom;
    Y := 20
  end;
    // Insert the watermark
    PDFDoc.InsertWatermark(Watermark,'1-3');
    Watermark.Free;
    PDFDoc.OpenAfterSave := True;
    PDFDoc.SaveToFile('PreDefined.pdf');
  end;

5. Run the application. Click 'Insert Predefined Variables' button on the form. This creates the page numbers and date in the output.pdf file for the first 3 pages. 

Insert user-defined variables

This tutorial explains about inserting user- defined variables to the place holders created in the PDF document.

Here is an application to insert user-defined variables:

1. Open Delphi/C++Builder application and drop PDFtoolkit component (TgtPDFDocument) to the form to load PDF document using the 'LoadFromFile' method.
2. Add a button to the form and change the caption property to 'Insert user-defined variables'.
3. Select PDFtoolkit component on the form and in the Object Inspector select 'OnCalcVariables' event. In the code window for OnCalcVariables event, define values to be passed as user variables and assign them to the respective place holders.

4. Create instance of 'TgtTextWatermarkTemplate' and create the place holders string and assign them to Text property of watermark. Create place holders as <%Var%> for assigning user defined variables.
5. For InsertWatermark method provide the watermark object along with the page numbers for creating the user-defined variables on these pages.

  Delphi:
    var
      Watermark: TgtTextWatermarkTemplate;
    begin
      PDFDoc.LoadFromFile('Input.pdf');
      PDFDoc.MeasurementUnit := muPixels;
      // Create and set watermark properties
      Watermark := TgtTextWatermarkTemplate.Create;
    with Watermark do
    begin

    // Create user defined variable 'Var' as placeholder 
        Text := 'Page <%PageNo%>, My variable is <%Var%>';
        Font.Name := 'Times New Roman';
        Font.Size := 15;
        Font.Style := [fsBold];
        RenderMode := rmFill;
        Overlay := False;
        HorizPos := hpCenter;
        VertPos := vpTop;
      end;
        // Insert the watermark
         PDFDoc.InsertWatermark(Watermark,'1-3');
         Watermark.Free;
          PDFDoc.OpenAfterSave := True;
          PDFDoc.SaveToFile('UserDefined.pdf');

        end;

        procedure TForm1.PDFDocCalcVariables(Sender: TgtCustomPDFDocument;
            Variable: WideString; var Value: WideString; PageNo: Integer);
         begin
           if (Variable = 'Var')and(PageNo = 1) then value := 'one';
           if (Variable = 'Var')and(PageNo = 2) then value := 'two';
           if (Variable = 'Var')and(PageNo = 3) then value := 'three';
          end;

  C++Builder:
    void __fastcall TForm1::Button2Click(TObject *Sender)
    {
      {
        TgtTextWatermarkTemplate * WaterMark;

      WaterMark = new TgtTextWatermarkTemplate();
      WaterMark->Text = "Page <%PageNo%> of <%TotPage%> where my var is <%var%> on Date <%ShortDate%> at <%LongTime%>";
      WaterMark->HorizPos = hpCenter;
      WaterMark->VertPos = vpTop;

      gtPDFDocument1->LoadFromFile("Input.pdf");
      gtPDFDocument1->InsertWatermark(WaterMark);
      gtPDFDocument1->SaveToFile("Output");

      delete WaterMark;
      }
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::gtPDFDocument1CalcVariables(
      TgtCustomPDFDocument *Sender, const WideString Variable,
      WideString &Value, int PageNo)
    {
      if ((PageNo % 2)== 0)
        Value = "Gnostice";
       else Value = "PDFtoolkit";

      }
6. Run the application. Click 'Insert user-defined variables' button. This will assign values 'One', 'Two', 'Three' as defined in the procedure to the placeholder (<%Var%>) in the output.pdf file for the first 3 pages.


Can I insert multiple or Composite Watermarks to my PDF document?
Yes, composite watermarks can be easily inserted using the TgtCompositeWatermarkTemplate class.

First, create any text or image watermarks and add them to an object of TgtCompositeWatermarkTemplate type. Then insert them all by calling the InsertWatermark method.

Stamping/Markings can be of type Text, Image or Composite. Click these links for watermark examples.

1. Text Watermark 
2. Image Watermark
3. Composite Watermark
4. Insert predefined variables
5. Insert user-defined variables

Text Watermark

To create an application to insert text watermark:

1. Open Delphi/C++Builder application and drop PDFtoolkit component (TgtPDFDocument) to the form to load PDF document using the 'LoadFromFile' method.
2. Then add a button to the form and change the button caption to 'Create Watermark' 
3. Double click the button and get to the Button's click event in the code editor. 
4. Paste the Delphi/C++Builder code mentioned below in the button's click event. 

Source Code
To create watermark declare 'TgtTextWatermarkTemplate' and set properties of text, angle, fonts etc. Once all the properties are set, use 'InsertWatermark' function to insert watermark to PDF document.

  Delphi:
  var
    Watermark: TgtTextWatermarkTemplate;
  begin
    // Create and set watermark properties
    PDFDoc.MeasurementUnit := muPixels;
    Watermark := TgtTextWatermarkTemplate.Create;
  with Watermark do
  begin
    Text := 'Gnostice PDFtoolkit';
    Angle := 45;
    Font.Name := 'Times New Roman';
    Font.Size := 40;
    Font.Style := [fsBold];
    RenderMode := rmStroke;
    StrokeColor := clMaroon;
    Overlay := True;
    HorizPos := hpCenter;
    VertPos := vpMiddle;
    // set this property to 'wmVertical' for Vertical text display
    WritingMode := wmVertical;
  end;
    // Insert the watermark
    PDFDoc.InsertWatermark(Watermark);
    Watermark.Free
  end;

  C++Builder:
      TgtTextWatermarkTemplate *Watermark;
    // Create and set watermark properties
    gtPDFDocument1->MeasurementUnit = muPixels;
    Watermark = new TgtTextWatermarkTemplate();
    Watermark->Text = "Gnostice PDFtoolkit";
    Watermark->Angle = 45;
    Watermark->Font->Name = "Times New Roman";
    Watermark->Font->Size = 40;
    Watermark->Font->Style = TFontStyles() << fsBold;
    Watermark->RenderMode = rmStroke;

    Watermark->StrokeColor = clMaroon;

    Watermark->Overlay = True;
    Watermark->HorizPos = hpCenter;
    Watermark->VertPos = vpMiddle;
    // set this property to 'wmVertical' for Vertical text display
    Watermark->WritingMode = wmVertical;
    // Insert the watermark
    gtPDFDocument1->InsertWatermark(Watermark);

    Watermark->Free();

5. Run the application. Click on 'Create Watermark' button on the form. View Watermark in the output.pdf file.

Image Watermark

In this example we will insert a bitmap image as watermark to a PDF document.
1. Open Delphi/C++Builder application and drop PDFtoolkit component (TgtPDFDocument) to the form to load PDF document using the 'LoadFromFile' method.
2. Then add a button to the form and change the button caption to 'Insert Bitmap Watermark' 
3. Double click the button and get to the Button's click event in the code editor. 
4. Paste the Delphi/C++Builder code mentioned below in the button's click event. 

  Delphi:
    var
      Watermark: TgtImageWatermarkTemplate;
      Bitmap: TBitmap;
    begin
      // Load image into bitmap
      Bitmap := TBitmap.Create;
      Bitmap.LoadFromFile('BitmapFile.bmp');
      // Create and set watermark properties
      Watermark := TgtImageWatermarkTemplate.Create;
      With Watermark do
      begin
        Image := Bitmap;
        Overlay := True;
        HorizPos := hpCenter;
        VertPos := vpMiddle;
       end;
        // Insert the watermark (assuming that gtPDFDocument1 is already loaded.)
        gtPDFDocument1.InsertWatermark(Watermark);
        FreeAndNil(Bitmap);
        FreeAndNil(Watermark);
      end; 

  C++Builder:
    TgtImageWatermarkTemplate *Watermark;
    Graphics::TBitmap *Bitmap;
    // Load image into bitmap
    Bitmap = new Graphics::TBitmap();
    Bitmap->LoadFromFile("BitmapFile.bmp");
    // Create and set watermark properties
    Watermark = new TgtImageWatermarkTemplate();
    Watermark->Image = Bitmap;
    Watermark->Overlay = True; 
    Watermark->HorizPos = hpCenter;
    Watermark->VertPos = vpMiddle;
    // Insert the watermark (assuming that gtPDFDocument1 is already loaded.)
    gtPDFDocument1->InsertWatermark(Watermark);
    Gtutils::FreeAndNil(Bitmap);
    Gtutils::FreeAndNil(Watermark);

5. Run the application. Click on 'Insert Bitmap Watermark' button on the form. Bitmap gets inserted to the PDF document.

Composite Watermark

This tutorial creates a composite watermark using text watermark and image watermark.

Follow the steps to create an application. 

1. Open Delphi/C++Builder application and drop PDFtoolkit component (TgtPDFDocument) to the form to load PDF document using the 'LoadFromFile' method. 
2. Then add a button to the form and change the button caption to 'Insert Composite Watermark' 
3. Double click the button and get to the Button's click event in the code editor. 
4. Paste the Delphi/C++Builder code mentioned below in the button's click event. 

  Delphi:
    var
      LWatermark: TgtCompositeWatermarkTemplate;
    begin
      LWatermark := TgtCompositeWatermarkTemplate.Create;
      LWatermark.AddWatermark(TextWatermark);
      LWatermark.AddWatermark(ImageWatermark);
      PDFDoc.InsertWatemark(LWatermark);
      FreeAndNil(LWatermark);
    end;

  C++Builder:
    TgtCompositeWatermarkTemplate *LWatermark;
    LWatermark = new TgtCompositeWatermarkTemplate();
    LWatermark->AddWatermark(TextWatermark);
    LWatermark->AddWatermark(ImageWatermark);
    gtPDFDocument1->InsertWatemark(LWatermark);
    FreeAndNil(LWatermark);
5. Run the application. Click 'Insert Composite Watermark' button on the form. This deletes the pages mentioned to be deleted and saves the file as output.pdf.

Insert predefined variables
This tutorial explains about inserting pre-defined variables (date, time, etc.) to the place holders created in the PDF document.
To insert predefined variables to the PDF document: 
1. Open Delphi/C++Builder application and drop PDFtoolkit component (TgtPDFDocument) to the form to load PDF document using the 'LoadFromFile' method.
2. Create instance of 'TgtTextWatermarkTemplate' class and set their properties.
3. Create the place holders string and assign them to Text property of watermark. Create place holders for page number(
<%PageNo%>), total number of pages(<%totPage%>) and date(<%Longdate%>).
4. Using InsertWatermark method provide the watermark object created along with the page numbers for creating the predefined variables on these pages of the output document.

Here is an application to insert predefined variables to a PDF document.

1. Open Delphi IDE.
2. Select 'PDFtoolkit' tab from the component palette and drag PDFtoolkit component to the Form.
3. Add a button to the form and change the caption property to 'Insert Predefined Variables'. 
4. Double click 'Insert Predefined Variables' button to open the code window. Paste the code for inserting text box in Button's onclick event.

  Delphi:
  var
    Watermark: TgtTextWatermarkTemplate;
  begin
    PDFDoc.LoadFromFile('Input.pdf');
    PDFDoc.MeasurementUnit := muPixels;
    // Create and set watermark properties
    Watermark := TgtTextWatermarkTemplate.Create;
    with Watermark do
    begin
      Text := 'Page <%PageNo%> of <%totPage%> , Date - <%Longdate%>';
      Font.Name := 'Times New Roman';
      Font.Size := 15;
      Font.Style := [fsBold];
      RenderMode := rmFill;
      Overlay := False;
      HorizPos := hpCenter;
      VertPos := vpCustom;
      Y := 20
    end;
     
// Insert the watermark
      PDFDoc.InsertWatermark(Watermark,'1-3');
      Watermark.Free;
      PDFDoc.OpenAfterSave := True;
      PDFDoc.SaveToFile('PreDefined.pdf');
    end;
5. Run the application. Click 'Insert Predefined Variables' button on the form. This creates the page numbers and date in the output.pdf file for the first 3 pages.

 
Insert user-defined variables

This tutorial explains about inserting user- defined variables to the place holders created in the PDF document.

Here is an application to insert user-defined variables:
1. Open Delphi/C++Builder application and drop PDFtoolkit component (TgtPDFDocument) to the form to load PDF document using the 'LoadFromFile' method.
2. Add a button to the form and change the caption property to 'Insert user-defined variables'.
3. Select PDFtoolkit component on the form and in the Object Inspector select 'OnCalcVariables' event. In the code window for OnCalcVariables event, define values to be passed as user variables and assign them to the respective place holders.
4. Create instance of 'TgtTextWatermarkTemplate' and create the place holders string and assign them to Text     property of watermark. Create place holders as <%Var%> for assigning user defined variables.
5. For InsertWatermark method provide the watermark object along with the page numbers for creating the user-defined variables on these pages.

  Delphi:
    var
      Watermark: TgtTextWatermarkTemplate;
    begin
      PDFDoc.LoadFromFile('Input.pdf');
      PDFDoc.MeasurementUnit := muPixels;
      // Create and set watermark properties
      Watermark := TgtTextWatermarkTemplate.Create;
      with Watermark do
      begin

      // Create user defined variable 'Var' as placeholder 
        Text := 'Page <%PageNo%>, My variable is <%Var%>';
        Font.Name := 'Times New Roman';
        Font.Size := 15;
        Font.Style := [fsBold];
        RenderMode := rmFill;
        Overlay := False;
        HorizPos := hpCenter;
        VertPos := vpTop;
      end;
      // Insert the watermark
      PDFDoc.InsertWatermark(Watermark,'1-3');
      Watermark.Free;
      PDFDoc.OpenAfterSave := True;
      PDFDoc.SaveToFile('UserDefined.pdf');

    end;

    procedure TForm1.PDFDocCalcVariables(Sender: TgtCustomPDFDocument;
      Variable: WideString; var Value: WideString; PageNo: Integer);
    begin
      if (Variable = 'Var')and(PageNo = 1) then value := 'one';
      if (Variable = 'Var')and(PageNo = 2) then value := 'two';
      if (Variable = 'Var')and(PageNo = 3) then value := 'three';
    end;

  C++Builder:
    void __fastcall TForm1::Button2Click(TObject *Sender)
    {
      {
        TgtTextWatermarkTemplate * WaterMark;

      WaterMark = new TgtTextWatermarkTemplate();
      WaterMark->Text = "Page <%PageNo%> of <%TotPage%> where my var is <%var%> on Date   <%ShortDate%> at <%LongTime%>";
      WaterMark->HorizPos = hpCenter;
      WaterMark->VertPos = vpTop;

      gtPDFDocument1->LoadFromFile("Input.pdf");
      gtPDFDocument1->InsertWatermark(WaterMark);
      gtPDFDocument1->SaveToFile("Output");

      delete WaterMark;
      }
    }
      //---------------------------------------------------------------------------
      void __fastcall TForm1::gtPDFDocument1CalcVariables(
        TgtCustomPDFDocument *Sender, const WideString Variable,
        WideString &Value, int PageNo)
      {
        if ((PageNo % 2)== 0)
          Value = "Gnostice";
        else Value = "PDFtoolkit";

        }

6. Run the application. Click 'Insert user-defined variables' button. This will assign values 'One', 'Two', 'Three' as defined in the procedure to the placeholder (<%Var%>) in the output.pdf file for the first 3 pages.


How do I insert a bitmap as Watermark?
Stamping/Markings can be of type Text, Image or Composite. Click these links for watermark examples.

1. Text Watermark 
2. Image Watermark
3. Composite Watermark
4. Insert predefined variables
5. Insert user-defined variables

Text Watermark
To create an application to insert text watermark:
1. Open Delphi/C++Builder application and drop PDFtoolkit component (TgtPDFDocument) to the form to load PDF document using the 'LoadFromFile' method.
2. Then add a button to the form and change the button caption to 'Create Watermark' 
3. Double click the button and get to the Button's click event in the code editor. 
4. Paste the Delphi/C++Builder code mentioned below in the button's click event. 

Source Code
To create watermark declare 'TgtTextWatermarkTemplate' and set properties of text, angle, fonts etc. Once all the properties are set, use 'InsertWatermark' function to insert watermark to PDF document.

  Delphi:
  var
    Watermark: TgtTextWatermarkTemplate;
  begin
    // Create and set watermark properties
    PDFDoc.MeasurementUnit := muPixels;
    Watermark := TgtTextWatermarkTemplate.Create;
  with Watermark do
  begin
    Text := 'Gnostice PDFtoolkit';
    Angle := 45;
    Font.Name := 'Times New Roman';
    Font.Size := 40;
    Font.Style := [fsBold];
    RenderMode := rmStroke;
    StrokeColor := clMaroon;
    Overlay := True;
    HorizPos := hpCenter;
    VertPos := vpMiddle;
    // set this property to 'wmVertical' for Vertical text display  
    WritingMode := wmVertical;
  end;
    // Insert the watermark
    PDFDoc.InsertWatermark(Watermark); 
    Watermark.Free;
  end;

  C++Builder:
    TgtTextWatermarkTemplate *Watermark;
    // Create and set watermark properties
    gtPDFDocument1->MeasurementUnit = muPixels;
    Watermark = new TgtTextWatermarkTemplate();
    Watermark->Text = "Gnostice PDFtoolkit";
    Watermark->Angle = 45;
    Watermark->Font->Name = "Times New Roman";
    Watermark->Font->Size = 40;
    Watermark->Font->Style = TFontStyles() << fsBold;
    Watermark->RenderMode = rmStroke;

    Watermark->StrokeColor = clMaroon;

    Watermark->Overlay = True;
    Watermark->HorizPos = hpCenter; 
    Watermark->VertPos = vpMiddle;
    // set this property to 'wmVertical' for Vertical text display
    Watermark->WritingMode = wmVertical;
    // Insert the watermark
    gtPDFDocument1->InsertWatermark(Watermark);

    Watermark->Free();

5. Run the application. Click on 'Create Watermark' button on the form. View Watermark in the output.pdf file.

Image Watermark

In this example we will insert a bitmap image as watermark to a PDF document.
1. Open Delphi/C++Builder application and drop PDFtoolkit component (TgtPDFDocument) to the form to load PDF document using the 'LoadFromFile' method.
2. Then add a button to the form and change the button caption to 'Insert Bitmap Watermark' 
3. Double click the button and get to the Button's click event in the code editor. 
4. Paste the Delphi/C++Builder code mentioned below in the button's click event. 

  Delphi:
    var

      Watermark: TgtImageWatermarkTemplate;
      Bitmap: TBitmap;

    begin
      // Load image into bitmap
      Bitmap := TBitmap.Create;
      Bitmap.LoadFromFile('BitmapFile.bmp');
      // Create and set watermark properties
      Watermark := TgtImageWatermarkTemplate.Create;
      With Watermark do
      begin
        Image := Bitmap;
        Overlay := True;
        HorizPos := hpCenter;
        VertPos := vpMiddle;
      end;
      // Insert the watermark (assuming that gtPDFDocument1 is already loaded.)
      gtPDFDocument1.InsertWatermark(Watermark);
      FreeAndNil(Bitmap);
      FreeAndNil(Watermark);
    end; 

  C++Builder:
    TgtImageWatermarkTemplate *Watermark;
    Graphics::TBitmap *Bitmap;
    // Load image into bitmap
    Bitmap = new Graphics::TBitmap();
    Bitmap->LoadFromFile("BitmapFile.bmp");
    // Create and set watermark properties
    Watermark = new TgtImageWatermarkTemplate();
    Watermark->Image = Bitmap;
    Watermark->Overlay = True;
    Watermark->HorizPos = hpCenter;
    Watermark->VertPos = vpMiddle;
    // Insert the watermark (assuming that gtPDFDocument1 is already loaded.)
    gtPDFDocument1->InsertWatermark(Watermark);
    Gtutils::FreeAndNil(Bitmap);
    Gtutils::FreeAndNil(Watermark);

5. Run the application. Click on 'Insert Bitmap Watermark' button on the form. Bitmap gets inserted to the PDF document.

Composite Watermark

This tutorial creates a composite watermark using text watermark and image watermark.

Follow the steps to create an application. 

1. Open Delphi/C++Builder application and drop PDFtoolkit component (TgtPDFDocument) to the form to load PDF document using the 'LoadFromFile' method. 
2. Then add a button to the form and change the button caption to 'Insert Composite Watermark' 
3. Double click the button and get to the Button's click event in the code editor. 
4. Paste the Delphi/C++Builder code mentioned below in the button's click event. 

  Delphi:
    var
      LWatermark: TgtCompositeWatermarkTemplate;
    begin
      LWatermark := TgtCompositeWatermarkTemplate.Create;
      LWatermark.AddWatermark(TextWatermark);
      LWatermark.AddWatermark(ImageWatermark);
      PDFDoc.InsertWatemark(LWatermark);
      FreeAndNil(LWatermark);
    end;

  C++Builder:
    TgtCompositeWatermarkTemplate *LWatermark;
    LWatermark = new TgtCompositeWatermarkTemplate();
    LWatermark->AddWatermark(TextWatermark);
    LWatermark->AddWatermark(ImageWatermark);
    gtPDFDocument1->InsertWatemark(LWatermark);
    FreeAndNil(LWatermark);

5. Run the application. Click 'Insert Composite Watermark' button on the form. This deletes the pages mentioned to be deleted and saves the file as output.pdf.

Insert predefined variables
This tutorial explains about inserting pre-defined variables (date, time, etc.) to the place holders created in the PDF document.

To insert predefined variables to the PDF document: 
1. Open Delphi/C++Builder application and drop PDFtoolkit component (TgtPDFDocument) to the form to load PDF document using the 'LoadFromFile' method.
2. Create instance of 'TgtTextWatermarkTemplate' class and set their properties.
3. Create the place holders string and assign them to Text property of watermark. Create place holders for page number(
<%PageNo%>), total number of pages(<%totPage%>) and date(<%Longdate%>).
4. Using InsertWatermark method provide the watermark object created along with the page numbers for creating the predefined variables on these pages of the output document.

Here is an application to insert predefined variables to a PDF document.
1. Open Delphi IDE.
2. Select 'PDFtoolkit' tab from the component palette and drag PDFtoolkit component to the Form.
3. Add a button to the form and change the caption property to 'Insert Predefined Variables'. 
4. Double click 'Insert Predefined Variables' button to open the code window. Paste the code for inserting text box in Button's onclick event.

  Delphi:
    var
      Watermark: TgtTextWatermarkTemplate;
    begin
      PDFDoc.LoadFromFile('Input.pdf');
      PDFDoc.MeasurementUnit := muPixels;
      // Create and set watermark properties
      Watermark := TgtTextWatermarkTemplate.Create;
    with Watermark do
    begin
      Text := 'Page <%PageNo%> of <%totPage%> , Date - <%Longdate%>';
      Font.Name := 'Times New Roman';
      Font.Size := 15;
      Font.Style := [fsBold];
      RenderMode := rmFill;
     Overlay := False;
      HorizPos := hpCenter;
      VertPos := vpCustom;
      Y := 20
    end;
      // Insert the watermark
      PDFDoc.InsertWatermark(Watermark,'1-3');
      Watermark.Free;
      PDFDoc.OpenAfterSave := True;
      PDFDoc.SaveToFile('PreDefined.pdf');
    end;

5. Run the application. Click 'Insert Predefined Variables' button on the form. This creates the page numbers and date in the output.pdf file for the first 3 pages. 

Insert user-defined variables

This tutorial explains about inserting user- defined variables to the place holders created in the PDF document.

Here is an application to insert user-defined variables:
1. Open Delphi/C++Builder application and drop PDFtoolkit component (TgtPDFDocument) to the form to load PDF document using the 'LoadFromFile' method.
2. Add a button to the form and change the caption property to 'Insert user-defined variables'.
3. Select PDFtoolkit component on the form and in the Object Inspector select 'OnCalcVariables' event. In the code window for OnCalcVariables event, define values to be passed as user variables and assign them to the respective place holders.
4. Create instance of 'TgtTextWatermarkTemplate' and create the place holders string and assign them to Text property of watermark. Create place holders as <%Var%> for assigning user defined variables.
5. For InsertWatermark method provide the watermark object along with the page numbers for creating the user-defined variables on these pages.

  Delphi:
    var
      Watermark: TgtTextWatermarkTemplate;
    begin
      PDFDoc.LoadFromFile('Input.pdf');
      PDFDoc.MeasurementUnit := muPixels;
      // Create and set watermark properties
      Watermark := TgtTextWatermarkTemplate.Create;
    with Watermark do
    begin
     // Create user defined variable 'Var' as placeholder 
      Text := 'Page <%PageNo%>, My variable is <%Var%>';
      Font.Name := 'Times New Roman';  
      Font.Size := 15;
      Font.Style := [fsBold];
      RenderMode := rmFill;
      Overlay := False;
      HorizPos := hpCenter;
      VertPos := vpTop;
    end;
    // Insert the watermark
      PDFDoc.InsertWatermark(Watermark,'1-3');
      Watermark.Free;
      PDFDoc.OpenAfterSave := True;
      PDFDoc.SaveToFile('UserDefined.pdf');

    end;

    procedure TForm1.PDFDocCalcVariables(Sender: TgtCustomPDFDocument;
    Variable: WideString; var Value: WideString; PageNo: Integer);
    begin
      if (Variable = 'Var')and(PageNo = 1) then value := 'one';
      if (Variable = 'Var')and(PageNo = 2) then value := 'two';
      if (Variable = 'Var')and(PageNo = 3) then value := 'three';
    end;

  C++Builder:

    void __fastcall TForm1::Button2Click(TObject *Sender)
    {
      {
        TgtTextWatermarkTemplate * WaterMark;

        WaterMark = new TgtTextWatermarkTemplate();
        WaterMark->Text = "Page <%PageNo%> of <%TotPage%> where my var is <%var%> on Date      <%ShortDate%> at <%LongTime%>";
        WaterMark->HorizPos = hpCenter;
        WaterMark->VertPos = vpTop;

        gtPDFDocument1->LoadFromFile("Input.pdf");
        gtPDFDocument1->InsertWatermark(WaterMark);
        gtPDFDocument1->SaveToFile("Output");

       delete WaterMark;
        }
      }
      //---------------------------------------------------------------------------
      void __fastcall TForm1::gtPDFDocument1CalcVariables(
        TgtCustomPDFDocument *Sender, const WideString Variable,
        WideString &Value, int PageNo)
      {
        if ((PageNo % 2)== 0)
          Value = "Gnostice";
        else Value = "PDFtoolkit";

        }

6. Run the application. Click 'Insert user-defined variables' button. This will assign values 'One', 'Two', 'Three' as defined in the procedure to the placeholder (<%Var%>) in the output.pdf file for the first 3 pages. 


How do I Set Values to form fields on a PDF form (Acroform) and permanently save the values?
Formfield values can be set using one of the following three methods provided by PDFtoolkit:

1. procedure SetFormFieldValue(FieldNo: Integer; Value: string);

- here, the function requires, the field index and its corresponding value.

2. procedure SetFormFieldValue(FieldName: string; Value: string);

- here, the function requires, the field name and its corresponding value.

3. procedure SetFormFields(Data: TStringList);

- here, the function requires, the field names and their corresponding values as Name-Value pairs in a string list.

All the field names and their corresponding existing values can be obtained by calling the "GetFormFields" function. The values for each field can be set by setting the 'Value' property, and then passing the StringList to SetFormFields.


How do I Extract Field Values from a filled PDF form?
Formfield values can be extracted from a filled PDF form using one of the following three functions:

1. function GetFormFieldValue(FieldNo: Integer): string;

  - Provide the field number whose value is to be extracted. The value is returned as string.

2. function GetFormFieldValue(FieldName: string): string;

  - Provide the field name of the field whose value is to be extracted.

The value is returned as string.

3. function GetFormFields: TStringList;

  - This function will return a string list of field names and values as Name-Value pairs.


How do I Extract Field Names from a PDF form?
Field names can be extracted by providing the index of the field in the PDF document.
In this example the formfield name is extracted from the PDF document containing formfields. Using the code provided below can extract formfield names from the PDF document.

  Delphi:
    var
      FldName: string;
    begin
      //fields are indexed from 0
      FldName := gtPDFDocument1.GetFormFieldName(1);   
    end;

  C++Builder:

    String FldName;
    //fields are indexed from 0
    FldName = gtPDFDocument1->GetFormFieldName(1);


How do I set my own Thumbnail for a specific page in the PDF document?
Thumbnails can be inserted to a PDF document using the AddThumbnail method. An object of TGraphic type has to be provided as input to the function. 
Thumbnails are added using the AddThumbnail method. An object of TGraphic type has to be provided as input to the function.

Follow the steps mentioned below to create an application to insert thumbnails for a PDF file.

1. Drop PDFtoolkit component (TgtPDFDocument) to the form and load PDF document using the 'LoadFromFile' method.
2. Then add a button to the form and change the button caption to 'Insert thumbnails' 
3. Double click the button and get to the Button's click event in the code editor. 
4. Paste the Delphi/C++Builder code mentioned below in the button's click event. 

  Delphi:
  var
    LImg: TBitmap;
  begin
    LImg := TBitmap.Create;
    LImg.LoadFromFile('Image1.bmp');
    PDFDoc.AddThumbnail(1, LImg);
    LImg.Free;
  end;

  C++Builder:
  Graphics::TBitmap *LImg;
  LImg = new Graphics::TBitmap();
  LImg->LoadFromFile("Image1.bmp");
  gtPDFDocument1->AddThumbnail(1, LImg);
  LImg->Free();

5. Run the application. Click 'Insert thumbnails' button on the form to create thumbnails. 


How do I Email a document after saving?
Enable the EMailWithFastNet or EMailWithIndy option in "gtPTKDefines.inc" to get built-in support for FastNet or Indy Components. "gtPTKDefines.inc" is located in the directory <InstallDir>\Source.

The information required for the EMail can be provided either through the event or through the EmailInfo property

.The PDF document generated by PDFtoolkit can be e-mailed as attachments. PDFtoolkit provides 'TgtEMailInfo' and 'TgtCustomPDFDocument' classes to support mailing feature. 

You can mail PDF documents using the Runtime Setup Dialog or can programmatically mailing using PDFtoolkit's component. For examples see 'Tutorial - Email'.

Follow these steps to configure mailing feature for PDFtoolkit before using PDFtoolkit to mail documents.

Configuring PDFtoolkit for Mailing 
For mailing through PDFtoolkit, you need to have e-mail components (Indy or FastNet) installed and configured with PDFtoolkit. PDFtoolkit supports two mailing components 'Indy' and 'FastNet'. Before mailing with PDFtoolkit need to configure PDFtoolkit with the supporting mailing components (Indy or Fastnet).
Configuration steps are as follows:
1. Install the third party component to support e-Mail in Delphi/C++Builder. The email component 'Indy' comes with Delphi but if you are using 'FastNet' need to install them. 
2. Configure PDFtoolkit's 'gtPTKDefines.inc' file.

a. Open the file from location "<PDFtoolkit Install Dir>/Source".
b. Search for the below mentioned code in the 'gtPTKDefines.inc'
    ---- E-Mail using FastNet units
    .$DEFINE EMailWithFastNet
    ---- E-Mail using Indy units
    .$DEFINE EMailWithIndy
    .$DEFINE Indy900Up 
3. The code mentioned above needs to be modified appropriately for e-mail support in PDFtoolkit.
Configure them for FastNet: If using 'FastNet' to send mails, replace '.$DEFINE EMailWithFastNet' to $DEFINE EMailWithFastNet by removing the dot. 

Configure them for Indy: If using 'Indy' to send mails, replace '.$DEFINE EMailWithIndy' to $DEFINE EMailWithIndyby removing the dot. Also for 'Indy' component, need to configure for versions. Suppose you have installed Indy with higher to version 9 we need to modify .$DEFINE Indy900Up to $DEFINE Indy900Up by removing the dot. Note: Do not modify the '
.$DEFINE Indy900Up' if you have installed Indy Version lower than 9.
4. After configuring for mailing save 'gtPTKDefines.inc' file and re-compile PDFtoolkit. Refer to "Re-Compiling PDFtoolkit" 

If Event method is used, then provide a handler for gtPDFDocument1.OnEmail event to set the E-Mail information.
 This tutorial guides to e-mail PDF document using PDFtoolkit's runtime setup dialog or programmatically mail the PDF files using 'TgtEMailInfo' and 'TgtCustomPDFDocument' components.

Mailing using setup dialog
Follow these steps to e-mail PDF document using PDFtoolkit's runtime setup dialog: 

1. Create an application using PDFtoolkit components to generate PDF document.
2. Run the application. This will pop up a runtime setup dialog. 
3. Select 'Email' tab to provide the mailing information. Select 'Email After Save' checkbox to activate mailing form. Provide Host, User ID and Password to connect the mailing server.
4. Click 'OK' to send PDF document as attachment.

Programmatically mailing using PDFtoolkit
Follow these steps to create e-mail application programmatically using PDFtoolkit components.

The information required for the EMail can be provided either through the event or through the EmailInfo property. If Event method is used, then provide a handler for gtPDFDocument1.OnEmail event to set the E-Mail information.

  Delphi:
    var

      LHost, LUserID, LPassword,
      LSubject, LReplyTo,
      LFromAddress, LFromName: string;
      LBody, LToAddress, LCCList, LBCCList: TStringList;
    begin
      gtPDFDocument1.EMailAfterSave := True;
    // Get Email information like Host, UserID, Password by poping a dialog from user or by other source.
    with gtPDFDocument1.EMailInfo do
    begin
      Host := LHost;
      UserID := LUserID;
      Password := LPassword;
      Date := Now;
      FromName := LFromName;
      FromAddress := LFromAddress;
      ReplyTo := LReplyTo;
      Subject := LSubject;
      RecipientList.Assign(LToAddress);
      CCList.Assign(LCCList);
      BCCList.Assign (LBCCList);
      Body.Assign(LBody);
    end;

    end;

  C++Builder:
    String LHost, LUserID, LPassword,LSubject, LReplyTo,LFromAddress, LFromName;
    TStringList *LBody, *LToAddress, *LCCList, *LBCCList;
     gtPDFDocument1->EMailAfterSave = True;
    // Get Email information like Host, UserID, Password by poping a dialog from user or by other source.
    gtPDFDocument1->EMailInfo->Host = LHost;
    gtPDFDocument1->EMailInfo->UserID = LUserID;
    gtPDFDocument1->EMailInfo->Password = LPassword;
    gtPDFDocument1->EMailInfo->Date = Now();
    gtPDFDocument1->EMailInfo->FromName = LFromName;
    gtPDFDocument1->EMailInfo->FromAddress = LFromAddress;
    gtPDFDocument1->EMailInfo->ReplyTo = LReplyTo;
    gtPDFDocument1->EMailInfo->Subject = LSubject;
    gtPDFDocument1->EMailInfo->RecipientList->Assign(LToAddress);
    gtPDFDocument1->EMailInfo->CCList->Assign(LCCList);
    gtPDFDocument1->EMailInfo->BCCList->Assign (LBCCList);
    gtPDFDocument1->EMailInfo->Body->Assign(LBody); 


How do I insert a Bookmark or Outline item to my PDF document?

Use CreateNewBookmark to create a new bookmark for the document. To manipulate an existing bookmark, call GetBookmarkRoot to obtain the root bookmark node of the document.

This tutorial explains about inserting new bookmarks and manipulating the existing bookmarks from the PDF documents.

There are two examples in this section:

a) Insert new bookmarks
b) Modify existing bookmarks
c) Load existing bookmark into a TreeView Control
d) Delete an existing node in a TreeView
e) Insert a new node
f) Modify an existing bookmark to associate with Actions
g) Create new bookmark to associate with Actions

Insert New Bookmarks

To insert a new bookmark for the document,
1. Drop PDFtoolkit component (TgtPDFDocument) to the form and load PDF document using the 'LoadFromFile' method.
2. Use the function CreateNewBookmark to create a new bookmark.
3. Create instances of TgtPDFOutline and TgtPDFDestination and use them to generate bookmarks with respect to the flow of the PDF document.
 
This application creates bookmarks for a PDF document using CreateNewBookmark function and also uses 'addchild' and 'addnext' functions as shown below. Follow the steps below:

1. Open Delphi/C++Builder application and add the PDFtoolkit component to the form. 
2. Then add a button to the form and change the button caption to 'Create Bookmark'
3. Double click the button and get to the Button's click event in the code editor.
4. Paste the Delphi/C++Builder code mentioned below in the button's click event.

  Delphi
    var

      Outline1, Outline2: TgtPDFOutline;
      PDFDst, PDFDst1: TgtPDFDestination;
    begin
      gtPDFDocument1.LoadFromFile('Input.pdf');
      PDFDst := TgtPDFDestination.Create(1, dtXYZ, 0, 0, 100);
      // Create new bookmark with title 'Chapter 1'.
      Outline1 := gtPDFDocument1.CreateNewBookmark('Chapter 1', PDFDst);
      PDFDst.Free;

      // Add 'Section 1' as child of 'Chapter 1'.
      PDFDst := TgtPDFDestination.Create(2, dtFitV);
      Outline1.AddChild('Section 1', PDFDst);
      PDFDst.Free;

      // Insert 'Chapter 2' as next bookmark node.

      PDFDst := TgtPDFDestination.Create(3, dtFit);
      Outline2 := Outline1.AddNext('Chapter 2', PDFDst);
      PDFDst := TgtPDFDestination.Create(4, dtFit);
      PDFDst1 := TgtPDFDestination.Create(5, dtFit);
      Outline2.AddChild('Section 1', PDFDst).AddNext('Section 2', PDFDst1);

      PDFDst.Free;
      PDFDst1.Free;
      PDFDst := TgtPDFDestination.Create(6, dtFitV);
      Outline2.AddNext('Chapter 3', PDFDst);
      PDFDst.Free;

        gtPDFDocument1.SaveToFile('Output.pdf'); 
    end;
  
  C++Builder:
    TgtPDFOutline *Outline1, *Outline2;
    TgtPDFDestination *PDFDst, *PDFDst1;
    gtPDFDocument1->LoadFromFile("Input.pdf");
    PDFDst = new TgtPDFDestination(1, dtXYZ, 0, 0, 100);
    // Create new bookmark with title 'Chapter 1'.
    Outline1 = gtPDFDocument1->CreateNewBookmark("Chapter 1", PDFDst);
    PDFDst->Free();

    // Add 'Section 1' as child of 'Chapter 1'.
    PDFDst = new TgtPDFDestination(2, dtFitV);

    Outline1->AddChild("Section 1", PDFDst);
    PDFDst->Free();
    // Insert 'Chapter 2' as next bookmark node.
    PDFDst = new TgtPDFDestination(3, dtFit);
    Outline2 = Outline1->AddNext("Chapter 2", PDFDst);
    PDFDst->Free();
    PDFDst = new TgtPDFDestination(4, dtFit);
    PDFDst1 = new TgtPDFDestination(5, dtFit);
    Outline2->AddChild("Section 1", PDFDst)->AddNext("Section 2", PDFDst1);
    PDFDst->Free();

    PDFDst1->Free();

    PDFDst = new TgtPDFDestination(6, dtFitV);
    Outline2->AddNext("Chapter 3", PDFDst);
    PDFDst->Free();
    gtPDFDocument1->SaveToFile("Output.pdf"');

5. Run the application. Click 'Create Bookmark' button on the form. View the Bookmarks created in 'output.pdf' file.

Modify Existing Bookmarks
To modify the existing bookmark for the PDF document,
1. Using TgtPDFDocument component, load the PDF document.
2. To manipulate an existing bookmark, call GetBookmarkRoot to obtain the root bookmark node of the document
3. Create instances of TgtPDFOutline and TgtPDFDestination and use them to manipulate the bookmarks as required. 

This application manipulates the bookmarks for a PDF document. For this example the input PDF file must have bookmarks. 

1. Open Delphi/C++Builder application and add the PDFtoolkit component to the form. 
2. Then add a button to the form and change the button caption to 'Modify Bookmark'
3. Double click the button and get to the Button's click event in the code editor.
4. Paste the Delphi/C++Builder code mentioned below in the button's click event.

  Deplhi:
  var

    Outline1, Outline2: TgtPDFOutline;
    PDFDst, PDFDst1: TgtPDFDestination;
  begin
    gtPDFDocument1.LoadFromFile('Input.pdf');

    // Obtain the root bookmark node of the document.
    Outline1 := gtPDFDocument1.GetBookmarkRoot.GetFirstChild;

    // Add 'Section 1' as child of Outline1.
    PDFDst := TgtPDFDestination.Create(2, dtFitV);
    Outline1.AddChild('Section 1', PDFDst);
    PDFDst.Free;

    // Insert 'Chapter 2' as next bookmark node.
    PDFDst := TgtPDFDestination.Create(3, dtFit);

    Outline2 := Outline1.AddNext('Chapter 2', PDFDst);
    PDFDst.Free;
    PDFDst := TgtPDFDestination.Create(4, dtFit);
    PDFDst1 := TgtPDFDestination.Create(5, dtFit);
    Outline2.AddChild('Section 1', PDFDst).AddNext('Section 2', PDFDst1);
    PDFDst.Free;
    PDFDst1.Free;
    PDFDst := TgtPDFDestination.Create(6, dtFitV);
    Outline2.AddNext('Chapter 3', PDFDst);
    PDFDst.Free;
    gtPDFDocument1.SaveToFile('output.pdf');
  end;

  C++Builder:
  TgtPDFOutline *Outline1, *Outline2;
  TgtPDFDestination *PDFDst, *PDFDst1;
  gtPDFDocument1->LoadFromFile("Input.pdf");
  // Obtain the root bookmark node of the document.
  Outline1 = gtPDFDocument1->GetBookmarkRoot()->GetFirstChild();
  //Outline1 = Outline1->GetFirstChild;

  // Add 'Section 1' as child of Outline1
  PDFDst = new TgtPDFDestination(2, dtFitV);
  Outline1->AddChild("Section 1", PDFDst);
  PDFDst->Free();

  // Insert 'Chapter 2' as next bookmark node.

  PDFDst = new TgtPDFDestination(3, dtFit);
  Outline2 = Outline1->AddNext("Chapter 2", PDFDst);
  PDFDst->Free();

  PDFDst = new TgtPDFDestination(4, dtFit);
  PDFDst1 = new TgtPDFDestination(5, dtFit);
  Outline2->AddChild("Section 1", PDFDst)->AddNext("Section 2", PDFDst1);
  PDFDst->Free();
  PDFDst1->Free();

  PDFDst = new TgtPDFDestination(6, dtFitV);
  Outline2->AddNext("Chapter 3", PDFDst);

  PDFDst->Free();
  gtPDFDocument1->SaveToFile("output.pdf"');

5. Run the application. Click 'Modify Bookmark' button on the form. View the Bookmarks created in 'output.pdf' file.

Load existing bookmark into a TreeView Control

This sample code explains about loading the existing bookmark of the PDF document to a TreeView Control. The code snippet for Delphi and C++Builder are provided below.
  
  Delphi:
      {
    Load all the bookmark nodes into a TreeView control.
    }

    procedure TForm1.LoadOutlines;
    var
      LOutline, LChild: TgtPDFOutline;
      LNode: TTreeNode;  
    begin
      LOutline := gtPDFDocument1.GetBookmarkRoot;
      if Assigned(LOutline) then
    begin
      // Obtain the first child of the root.
      LChild := LOutline.GetFirstChild;
    if Assigned(LChild) then
    begin
      // Add the Child node to the TreeView, and attach the pointer to it to that node.
      LNode := TreeView1.Items.AddObject(nil, LChild.Title, LChild);
      if LChild.Child <> nil then
      BuildOutlineChild(LNode, LChild.Child);
      if LChild.Next <> nil then
      BuildOutlineNext(LNode, LChild.Next);
    end;
    end;
    end
;

    {
    Recursively build all the children.
    aNode - the TTreeNode item to which aOutline is to be added as child.
    aOutline - the current outline node to be added as child item to the TreeView Node.
    }

    procedure TForm1.BuildOutlineChild(aNode: TTreeNode; aOutline: TgtPDFOutline);

    var
    LNode: TTreeNode;

    begin
    // Add aOutline as Child to aNode in the TreeView.
    LNode := TreeView1.Items.AddChildObject(aNode, aOutline.Title, aOutline);

    if aOutline.Child <> nil then
    BuildOutlineChild(LNode, aOutline.Child);
    if aOutline.Next <> nil then
    BuildOutlineNext(LNode, aOutline.Next);
   end;
    {
    Recursively build all the siblings.
    aNode - the TTreeNode item to which aOutline is to be added as sibling.
    aOutline - the current outline node to be added as sibling of aNode. 
     }

    procedure TForm1.BuildOutlineNext(aNode: TTreeNode; aOutline: TgtPDFOutline);

    var
    LNode: TTreeNode;

    begin
    // Add aOutline as sibling to aNode in the TreeView.
    LNode := TreeView1.Items.AddObject(aNode, aOutline.Title, aOutline);
    if aOutline.Child <> nil then
    BuildOutlineChild(LNode, aOutline.Child);
    if aOutline.Next <> nil then
    BuildOutlineNext(LNode, aOutline.Next);
  end;

  C++ Builder:
    /*
    Load all the bookmark nodes into a TreeView control.
    */

    void TForm1::LoadOutlines()
    {
    TgtPDFOutline *LOutline, *LChild;
    TTreeNode *LNode;
    LOutline = gtPDFDocument1->GetBookmarkRoot();
    if (LOutline != NULL)
    {
    // Obtain the first child of the root.
    LChild = LOutline->GetFirstChild();
    if (LChild != NULL)
    {
    // Add the Child node to the TreeView, and attach the pointer to it to that node.
    LNode = TreeView1->Items->AddObject(NULL, LChild->Title, LChild);
    if (LChild->Child != NULL)
    BuildOutlineChild(LNode, LChild->Child);
    if (LChild->Next != NULL)
    BuildOutlineNext(LNode, LChild->Next);
    }
    }
    }
    /*
    Recursively build all the children.
    aNode - the TTreeNode item to which aOutline is to be added as child.
    aOutline - the current outline node to be added as child item to the TreeView Node.
    */

    void TForm1::BuildOutlineChild(TTreeNode *aNode, TgtPDFOutline *aOutline)
    {
    TTreeNode *LNode;
    // Add aOutline as Child to aNode in the TreeView.
    LNode = TreeView1->Items->AddChildObject(aNode, aOutline->Title, aOutline);
    if (aOutline->Child != NULL)
    BuildOutlineChild(LNode, aOutline->Child);
    if (aOutline->Next != NULL)
    BuildOutlineNext(LNode, aOutline->Next);
    }

    /*
    Recursively build all the siblings.
    aNode - the TTreeNode item to which aOutline is to be added as sibling.
    aOutline - the current outline node to be added as sibling of aNode.
    */

    void TForm1::BuildOutlineNext(TTreeNode *aNode, TgtPDFOutline *aOutline)
    {
    TTreeNode *LNode;
    // Add aOutline as sibling to aNode in the TreeView.
    LNode = TreeView1->Items->AddObject(aNode, aOutline->Title, aOutline);
    if (aOutline->Child != NULL)
    BuildOutlineChild(LNode, aOutline->Child);
    if (aOutline->Next != NULL)
    BuildOutlineNext(LNode, aOutline->Next);
    }

Delete an existing node in a TreeView
This sample code explains about deleting the existing bookmark of the PDF document. The code snippet for  Delphi and C++Builder are provided below.

  Delphi:
    var

      LNode: TTreeNode;
    begin
      // If the selected node has previous sibling, then...
      LNode := TreeView1.Selected.getPrevSibling;
      if Assigned(LNode) then
      begin
        TgtPDFOutline(LNode.Data).DeleteNext;
        TreeView1.Selected.Delete;
      end
      else
// else obtain the parent node of the selected node.
      begin
        LNode := TreeView1.Selected.Parent;
        if Assigned(LNode) then
        begin
          TgtPDFOutline(LNode.Data).DeleteChild;
          TreeView1.Selected.Delete;
         end
        else
// else, if it does not have parent, then...
        begin
          gtPDFDocument1.GetBookmarkRoot.DeleteChild;
          TreeView1.Selected.Delete;
        end;
      end;
    end;

  C++Builder:
    TTreeNode *LNode;
    // If the selected node has previous sibling, then...
    LNode = TreeView1->Selected->getPrevSibling();
    if (LNode != NULL)
    {
      ((TgtPDFOutline *)(LNode->Data))->DeleteNext();
      TreeView1->Selected->Delete();
    }
    else // else obtain the parent node of the selected node.
    {
      LNode = TreeView1->Selected->Parent;
      if (LNode != NULL)
      {
        ((TgtPDFOutline*)LNode->Data)->DeleteChild();
        TreeView1->Selected->Delete();
    }
    else // else, if it does not have parent, then...
    {
      gtPDFDocument1->GetBookmarkRoot()->DeleteChild();
  &