Developer Tools
|
Office Productivity Applications
|
Enterprise Solutions
|
|||||||||||||||||||||||||||
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}.
* - The file gtPTKDefines.Inc is present in the source folder where PDFtoolkit was installed.
| Privacy | Legal | Feedback | Newsletter | © 2002-2009 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 users are advised to use Microsoft ClearType Tuning for optimal experience. Linux and other users can enable font smoothing, as supported by their OS. Also, please use the latest version of a standards-compliant browser such as Opera, FireFox, Chrome or Safari.