PdfForm Object

Overview

PdfForm represents an interactive form associated with this document. PdfForm is obtainable via PdfDocument's Form property. For more information on interactive forms, see Chapter 11 - Forms.

Member List

Properties


PdfAnnots Fields (Read-only)
Returns a PdfAnnots collection of PdfAnnot objects representing individual top-level form fields.

bool HasXFA (Read-only)

Returns True if the PDF form contains XFA data. Otherwise returns False. This property was introduced in Version 3.0.

For more information, see Section 12.7 - XFA Support.


bool NeedAppearances (Read-only)
Returns or specifies a flag controlling whether to construct appearances for all form fields in the document. False by default.

int SigFlags (Read/Write)

Returns or specifies signature flags. The following flag bits are defined:

Bit 1: If set, the document contains at least one signature field.
Bit 2: If set, the document contains signatures that may be invalidated if the file is saved (written) in a way that alters its previous contents (such as with the "optimize" option). Merely updating the file by appending new information to the end of the previous version is safe.


string XFADatasets (Read/Write)

Returns or specifies the PDF form's XFA dataset in XML format. Can only be used if the HasXFA property returns True. This property was introduced in Version 3.0.

For more information, see Section 12.7 - XFA Support.


string XFATemplate (Read-only)

Returns the PDF form's XFA template in XML format. Can only be used if the HasXFA property returns True. This property was introduced in Version 3.0.

For more information, see Section 12.7 - XFA Support.

Methods


PdfAnnot FindField(string Name)

Finds and returns a top-level form field specified by Name. If no fields under this name are found, the method returns null.

This method is useful for automatic form fill-out purposes.

The Form Field Finder online application enables you to determine which field names your PDF form supports.

Usage:

PdfDocument objDoc = objPDF.OpenDocument( @"c:\1040nr.pdf" );
PdfAnnot objField = ovhDoc.Form.FindField("txtFirstName");
objField.SetFieldValue( "John", objFont );

For more information, see Chapter 12 - Existing Form Fill-in.


void Flatten()

Flattens the form, i.e. turns all of its interactive fields into static graphics. This method should only be called on an already filled-in form. This method was introduced in Version 2.6.

Usage:

PdfDocument objDoc = objPdf.OpenDocument( @"c:\path\1040nr.pdf" );
objDoc.Form.Flatten();
objDoc.Save( @"c:\path\flattened.pdf" );

For more information, see Section 12.5 - Form Flattening.


void Modify(object Param)

Performs various operations on the form based on the specified parameters.

Param is a PdfParam object or parameter string containing various Boolean parameters, all optional, including:

  • RemoveXFA - this parameter is equivalent to calling the RemoveXFA method.
  • Flatten - this parameter is equivalent to calling the Flatten method.
  • FlattenAnnots - this parameter flattens items that are not technically form fields but field-like annotations.
  • RemoveJavaScript - this parameter removes all JavaScript from the document's catalog. This prevents the message "This PDF form requires a newer version of Adobe Acrobat" from popping up.
  • Reset - this parameter resets the current graphics state for all pages of the document. This may be useful if the flattening procedure produces unexpected output or no output at all. This parameter was introduced in Version 3.4.0.30931.

This method was introduced in Version 2.9.

Usage:

PdfDocument objDoc = objPdf.OpenDocument(@"c:\path\1040nr.pdf");
objDoc.Form.Modify( "Flatten=true; RemoveJavaScript=true" );
objDoc.Save( @"c:\path\flattened.pdf" );

For more information, see Section 12.6 - JavaScript Removal and Other Features.


void RemoveXFA()

Removes the XML Forms Architecture (XFA) information from an existing form. This method is a workaround addressing partial incompatibility between AspPDF.NET and forms created by Adobe Designer 7.0+.

Usage:

PdfDocument objDoc = objPDF.OpenDocument( @"c:\1040nr.pdf" );
objDoc.Form.RemoveXFA();

' Fill in the form
...

For more information, see Section 12.2 - Adobe Acrobat 7/Designer 7 Issues.