Class PdfAcroForm
The interactive form (AcroForm) of a document: read, fill, create and flatten fields. Obtain it with GetForm() or GetOrCreateForm().
public sealed class PdfAcroForm
- Inheritance
-
PdfAcroForm
- Inherited Members
Properties
AppearanceFont
Font used for generated appearances when a field does not specify one. Set an embedded PdfTrueTypeFont to fill in characters outside WinAnsi (e.g. Polish, Cyrillic).
public PdfFont? AppearanceFont { get; set; }
Property Value
Dictionary
The AcroForm dictionary (/AcroForm in the document catalog).
public PdfDictionary Dictionary { get; }
Property Value
Document
The document the form belongs to.
public PdfDocument Document { get; }
Property Value
Fields
All terminal fields (fields that hold a value) in document order.
public IReadOnlyList<PdfFormField> Fields { get; }
Property Value
NeedAppearances
Asks viewers to regenerate appearances (/NeedAppearances).
public bool NeedAppearances { get; set; }
Property Value
Xfa
The XFA part of the form (data of XFA forms).
public XfaForm Xfa { get; }
Property Value
Methods
AddCheckBox(PdfPage, string, PdfRectangle, bool, PdfColor?, CheckBoxStyle, double, PdfColor?)
Adds a check box with the on-state "Yes". The border is drawn in border (default black) with
borderWidth points; a width of 0 means no border. Like text fields, the check box has no
background unless background is set, so it does not cover the page content below it.
public PdfCheckBox AddCheckBox(PdfPage page, string name, PdfRectangle rect, bool isChecked = false, PdfColor? border = null, CheckBoxStyle style = CheckBoxStyle.Check, double borderWidth = 1, PdfColor? background = null)
Parameters
pagePdfPagenamestringrectPdfRectangleisCheckedboolborderPdfColor?styleCheckBoxStyleborderWidthdoublebackgroundPdfColor?
Returns
AddComboBox(PdfPage, string, PdfRectangle, IEnumerable<string>, string?, bool, PdfColor?, PdfColor?, double)
Adds a combo box (drop-down list) with a border in border (default black, width 0 = no border)
and no background unless background is set.
public PdfChoiceField AddComboBox(PdfPage page, string name, PdfRectangle rect, IEnumerable<string> options, string? selected = null, bool editable = false, PdfColor? border = null, PdfColor? background = null, double borderWidth = 1)
Parameters
pagePdfPagenamestringrectPdfRectangleoptionsIEnumerable<string>selectedstringeditableboolborderPdfColor?backgroundPdfColor?borderWidthdouble
Returns
AddListBox(PdfPage, string, PdfRectangle, IEnumerable<string>, string?, bool, PdfColor?, PdfColor?, double)
Adds a list box with a border in border (default black, width 0 = no border) and no
background unless background is set.
public PdfChoiceField AddListBox(PdfPage page, string name, PdfRectangle rect, IEnumerable<string> options, string? selected = null, bool multiSelect = false, PdfColor? border = null, PdfColor? background = null, double borderWidth = 1)
Parameters
pagePdfPagenamestringrectPdfRectangleoptionsIEnumerable<string>selectedstringmultiSelectboolborderPdfColor?backgroundPdfColor?borderWidthdouble
Returns
AddPushButton(PdfPage, string, PdfRectangle, PdfImage?, string?, PdfColor?, PdfColor?)
Adds a push button showing an image (icon only) and/or a caption, e.g. to place a signature image as a form field without a digital signature.
public PdfPushButton AddPushButton(PdfPage page, string name, PdfRectangle rect, PdfImage? icon = null, string? caption = null, PdfColor? border = null, PdfColor? background = null)
Parameters
pagePdfPagenamestringrectPdfRectangleiconPdfImagecaptionstringborderPdfColor?backgroundPdfColor?
Returns
AddRadioGroup(PdfPage, string, IEnumerable<(string Value, PdfRectangle Rect)>, string?, PdfColor?, PdfColor?, double)
Adds a radio button group with one button per option.
public PdfRadioButtonGroup AddRadioGroup(PdfPage page, string name, IEnumerable<(string Value, PdfRectangle Rect)> options, string? selected = null, PdfColor? border = null, PdfColor? background = null, double borderWidth = 1)
Parameters
pagePdfPagePage of the buttons.
namestringField name.
optionsIEnumerable<(string Value, PdfRectangle Rect)>Export value and rectangle of every button.
selectedstringInitially selected export value.
borderPdfColor?Border color (default black).
backgroundPdfColor?Background color (default none, so the page content below stays visible).
borderWidthdoubleBorder width in points; 0 = no border.
Returns
AddSignatureField(PdfPage, string, PdfRectangle)
Adds an empty signature field (use an empty rectangle for an invisible signature).
public PdfSignatureField AddSignatureField(PdfPage page, string name, PdfRectangle rect)
Parameters
pagePdfPagenamestringrectPdfRectangle
Returns
AddTextField(PdfPage, string, PdfRectangle, string?, double, bool, PdfColor?, PdfColor?, double)
Adds a text field. A font size of 0 means auto-size. The border is drawn in border (default
black) with borderWidth points; a width of 0 means no border.
public PdfTextField AddTextField(PdfPage page, string name, PdfRectangle rect, string? value = null, double fontSize = 0, bool multiline = false, PdfColor? border = null, PdfColor? background = null, double borderWidth = 1)
Parameters
pagePdfPagenamestringrectPdfRectanglevaluestringfontSizedoublemultilineboolborderPdfColor?backgroundPdfColor?borderWidthdouble
Returns
ExportFdf(string?)
Exports the field values as FDF (Forms Data Format, ISO 32000-1, 12.7.8), the binary counterpart of XFDF that Acrobat and many form tools read. Same scope as ExportXfdf(string?).
public byte[] ExportFdf(string? pdfFileName = null)
Parameters
pdfFileNamestringOptional file name of the PDF the data belongs to (/F).
Returns
- byte[]
ExportXfdf(string?)
Exports the field values as XFDF (XML Forms Data Format, ISO 19444-1): text fields, check boxes, radio groups,
combo and list boxes (several <value> elements for multiple selections). Fields without a value,
push buttons and signature fields are left out. Hierarchical names ("address.street") become nested fields.
public string ExportXfdf(string? pdfFileName = null)
Parameters
pdfFileNamestringOptional file name of the PDF the data belongs to (
<f href>).
Returns
Flatten(IEnumerable<PdfFormField>?)
Flattens the given fields (all if null): their current appearance becomes part of the page content and the fields are removed. The values can no longer be edited.
public void Flatten(IEnumerable<PdfFormField>? fields = null)
Parameters
fieldsIEnumerable<PdfFormField>
GetField(string)
Returns the field with the given fully qualified name, or null.
public PdfFormField? GetField(string fullName)
Parameters
fullNamestring
Returns
GetField<T>(string)
Returns the field with the given fully qualified name if it is of type T, otherwise null.
public T? GetField<T>(string fullName) where T : PdfFormField
Parameters
fullNamestring
Returns
- T
Type Parameters
T
GetValues()
Returns all field values as name โ Value (for choice fields with several selected options the first one; see SelectedValues).
public IReadOnlyDictionary<string, string?> GetValues()
Returns
ImportFdf(byte[])
Imports ("merges") field values from FDF data (ISO 32000-1, 12.7.8) into this form: hierarchical fields (/Kids) and flat names are supported; unknown fields are reported in UnknownFields. Appearances are regenerated. Annotations, embedded files and JavaScript in the FDF are ignored.
public FormDataImportResult ImportFdf(byte[] fdf)
Parameters
fdfbyte[]
Returns
Exceptions
- PdfException
The data is not FDF or cannot be parsed.
ImportXfdf(Stream)
Imports field values from an XFDF stream (see ImportXfdf(string)).
public FormDataImportResult ImportXfdf(Stream xfdf)
Parameters
xfdfStream
Returns
ImportXfdf(string)
Imports field values from XFDF (ISO 19444-1). Nested and flat field names ("address.street") are accepted; unknown fields are reported in UnknownFields. Appearances are regenerated. DTDs are not processed, so untrusted data can be imported safely. Annotations in the XFDF are ignored.
public FormDataImportResult ImportXfdf(string xfdf)
Parameters
xfdfstring
Returns
Exceptions
- PdfException
The data is not well-formed XML or not XFDF.
RemoveField(PdfFormField)
Removes a field and its widgets.
public void RemoveField(PdfFormField field)
Parameters
fieldPdfFormField
SetValue(string, string?)
Sets the value of a field by name (text, check box state, radio option, choice).
public void SetValue(string fullName, string? value)