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

Fill, Flatten, and Email PDF Forms

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

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 interactivity feaures 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.

var
  LI: Integer;
  LFormField: TgtFormField;
  LBody: TStringList;
begin
  PDFDoc.EMailAfterSave := True;
  // Load the document
  PDFDoc.LoadFromFile('InputFile.pdf');
  // Process each form fields in the document
  for LI := 0 to PDFDoc.GetFormFieldCount - 1 do
  begin
    LFormField := PDFDoc.GetFormField(LI);
    // Check if it is a text field
    if LFormField.FieldType = ftText then
    begin
      // Fill the text form field
      LFormField.FieldValue := 'Text to be filled';
    end;
  end;
  // Flatten all form fields on all pages
  PDFDoc.FlattenFormFieldsOnPage(
              '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
  begin
    // Smtp server
    Host := '192.168.10.1';

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

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

    // E-mail recipients
    RecipientList.Add('shine@gnostice.com');
    RecipientList.Add('mohammed@gnostice.com');
  end;

  PDFDoc.ShowSetupDialog := False;

  // Save the document to file
  PDFDoc.SaveToFile('Output.pdf'); 
  // This step also mails the document to the recipients
end;

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}.

---o0O0o---

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

---o0O0o---

Our Developer Tools
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.

XtremePDFConverter VCL

A Delphi/C++Builder component to intelligently convert PDF to user-friendly Word RTF documents.

PDFOne .NET

A .NET PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, and bookmark PDF documents in .NET applications.

XtremeDocumentStudio .NET

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

PDFOne (for Java™)

A Java™ PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, bookmark PDF documents in Java™ applications.

XtremeFontEngine (for Java)

Java font engine to render glyphs from Type 1, Type 2 (CFF), and TrueType fonts

Our Office Productivity Applications
Free PDF Reader

A free, fast, and portable application for viewing, printing and converting PDF documents.

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

This site is best viewed on a screen with minimum resolution of 1152 x 864 pixels. Windows XP users are advised to use Microsoft ClearType Tuning for optimal experience. Also, please use the latest version of a standards-compliant browser such as Firefox, Opera, or Dragon (Chromium).