PDFtoolkit VCL
Edit, enhance, secure, merge, split, view, print PDF and AcroForms documents
Delphi C++Builder

Fill, Flatten, and Email PDF Forms

Learn how to flatten PDF forms and have them automatically e-mailed.
By Mohammed Najeemudheen

With the release of Version 4 of PDFtoolkit, form field processing has got simpler. PDF-to-image conversion is much more simpler. A special article titled "Form Fields Creation and Processing Using PDFtoolkit v4" has been written for users of Version 4. This article has been left here for users of older versions of PDFtoolkit.

A flattened PDF form field is uneditable. When you flatten a form field, you remove its interactive features and change its appearance so as to make the value entered or selected in it appear like regular text. PDF documents with flattened form fields are useful if you want them for archival or distribution purposes.

PDFtoolkit VCL allows you to fill and flatten PDF form fields. It also supports automatic e-mailing of PDF documents. In this article, you will learn about all three tasks - filling, flattening, and e-mail PDF forms.

First, drop a TgtPDFDocument object and a button on your form. Now, add the following code segment to the click event of the button.

  LI: Integer;
  LFormField: TgtFormField;
  LBody: TStringList;
  PDFDoc.EMailAfterSave := True;
  // Load the document
  // Process each form fields in the document
  for LI := 0 to PDFDoc.GetFormFieldCount - 1 do
    LFormField := PDFDoc.GetFormField(LI);
    // Check if it is a text field
    if LFormField.FieldType = ftText then
      // Fill the text form field
      LFormField.FieldValue := 'Text to be filled';
  // Flatten all form fields on all pages
              '1-' + IntToStr(PDFDoc.PageCount));

  LBody := TStringList.Create;
  LBody.Add('This is a test.');

  // Specify settings for the e-mail with which
  // the document is attached and sent
  with PDFDoc.EMailInfo do
    // Smtp server
    Host := '';

    UserID := 'mohamed';
    Password := '***';
    FromAddress := 'mohamed@gnostice.com';

    Body := LBody;
    Date := Now;
    FromName:= 'Najeeb';
    Subject := 'Testing';
    AuthenticationRequired := True;

    // E-mail recipients

  PDFDoc.ShowSetupDialog := False;

  // Save the document to file
  // This step also mails the document to the recipients

When you click the button, a PDF forms document InputFile.pdf will be loaded. All text form fields in the document will be filled with string "Text to be filled". Next, the form fields will be flattened. Finally, the forms documents will be saved to a file Output.pdf. This action automatically e-mails the document to recipients specified in the EMailInfo.

If you need to have PDF documents mailed like this, then you need to enable the switch {$DEFINE EMailWithFastNet} or {$DEFINE EMailWithIndy} in the file gtPTKDefines.Inc.* If you choose the latter, you also need to enable another switch {$DEFINE Indy900Up}.


* - The file gtPTKDefines.Inc is present in the source folder where PDFtoolkit was installed.


Our .NET Developer Tools
Gnostice Document Studio .NET

Multi-format document-processing component suite for .NET developers.


A .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 Delphi

Multi-format document-processing component suite for Delphi/C++Builder developers, covering both VCL and FireMonkey platforms.

eDocEngine VCL

A Delphi/C++Builder component suite for creating documents in over 20 formats and also export reports from popular Delphi reporting tools.

PDFtoolkit VCL

A 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 Java

Multi-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

Cloud-hosted and On-Premises REST-based document-processing and document-viewing APIs

Privacy | Legal | Feedback | Newsletter | Blog | Resellers © 2002-2024 Gnostice Information Technologies Private Limited. All rights reserved.