Click or drag to resize
Pdf Library for .NET

PdfFormManager Class

Reads and fills the AcroForm fields of an existing PDF document. Load a document with one of the Load overloads, read or set values through Fields, then persist the changes with Save(String) / GetDocument.
Inheritance Hierarchy
SystemObject
  SelectPdf.UniversalPdfFormManager

Namespace: SelectPdf.Universal
Assembly: SelectPdf.Universal (in SelectPdf.Universal.dll) Version: 26.4
Syntax
public class PdfFormManager

The PdfFormManager type exposes the following members.

Constructors
 NameDescription
Public methodPdfFormManager Initializes a new instance of the PdfFormManager class. Call one of the Load overloads before accessing Fields.
Top
Properties
 NameDescription
Public propertyCode exampleCompactSave Gets or sets a value indicating whether the document is rewritten from scratch on save instead of being updated incrementally. Default is false.
Public propertyFields Gets the collection of form fields in the loaded document. A document with no AcroForm - which is the state a document is in after Flatten and a save - returns an EMPTY collection, not null, so manager.Fields.Count is always safe to read.
Public propertyFlattenGets or sets a value indicating whether the whole form is flattened on save.
Public propertyReadOnly Gets or sets a value indicating whether the pdf form is read-only or not.
Top
Methods
 NameDescription
Public methodCloseCloses the loaded document and releases its resources.
Public methodGetDocument Serializes the current state and returns it as a new PdfDocument for further processing (adding pages, merging, applying security, etc.).
Public methodLoad(Byte)Loads a PDF document from a byte array.
Public methodLoad(PdfDocument)Loads the AcroForm of an existing PdfDocument.
Public methodLoad(Stream)Loads a PDF document from a stream.
Public methodCode exampleLoad(String)Loads a PDF document from a file.
Public methodLoad(Byte, String)Loads a password-protected PDF document from a byte array.
Public methodLoad(PdfDocument, String)Loads an existing PdfDocument with a password.
Public methodLoad(Stream, String)Loads a password-protected PDF document from a stream.
Public methodLoad(String, String)Loads a password-protected PDF document from a file.
Public methodSaveSaves the document (with any field changes) and returns the bytes.
Public methodSave(Stream)Saves the document (with any field changes) to a stream.
Public methodCode exampleSave(String)Saves the document (with any field changes) to a file.
Top
Remarks

Fonts. A field is drawn in the font the form itself specifies. When that font cannot encode the value — a form built for Latin text given Greek, Japanese or mathematical symbols — a font that can is chosen from the ones installed on the machine, so the value is visible and extractable rather than silently blank. If a character still does not appear, no installed font covers it: installing one is the fix. The directories searched are %SystemRoot%\Fonts on Windows, /Library/Fonts and ~/Library/Fonts on macOS, and /usr/share/fonts, ~/.fonts and ~/.local/share/fonts on Linux.

It must be an outline font. A colour-bitmap face — Apple Color Emoji, Noto Color Emoji — stores its glyphs as images rather than outlines, so it cannot be embedded in a PDF and is skipped; a monochrome equivalent such as Noto Emoji works. One value is drawn in one font, so a value mixing scripts that no single installed font covers keeps only the part that font has.

Example
PdfFormManager manager = new PdfFormManager();
manager.Load("form.pdf");
PdfFormFieldTextBox name =
    manager.Fields["name"] as PdfFormFieldTextBox;
if (name != null) name.Text = "John Doe";
manager.Save("filled.pdf");
manager.Close();
See Also