Table of Contents

Class PdfAcroForm

Namespace
MiPdf.Forms
Assembly
MiPdf.dll

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

PdfFont

Dictionary

The AcroForm dictionary (/AcroForm in the document catalog).

public PdfDictionary Dictionary { get; }

Property Value

PdfDictionary

Document

The document the form belongs to.

public PdfDocument Document { get; }

Property Value

PdfDocument

Fields

All terminal fields (fields that hold a value) in document order.

public IReadOnlyList<PdfFormField> Fields { get; }

Property Value

IReadOnlyList<PdfFormField>

NeedAppearances

Asks viewers to regenerate appearances (/NeedAppearances).

public bool NeedAppearances { get; set; }

Property Value

bool

Xfa

The XFA part of the form (data of XFA forms).

public XfaForm Xfa { get; }

Property Value

XfaForm

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

page PdfPage
name string
rect PdfRectangle
isChecked bool
border PdfColor?
style CheckBoxStyle
borderWidth double
background PdfColor?

Returns

PdfCheckBox

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

page PdfPage
name string
rect PdfRectangle
options IEnumerable<string>
selected string
editable bool
border PdfColor?
background PdfColor?
borderWidth double

Returns

PdfChoiceField

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

page PdfPage
name string
rect PdfRectangle
options IEnumerable<string>
selected string
multiSelect bool
border PdfColor?
background PdfColor?
borderWidth double

Returns

PdfChoiceField

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

page PdfPage
name string
rect PdfRectangle
icon PdfImage
caption string
border PdfColor?
background PdfColor?

Returns

PdfPushButton

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

page PdfPage

Page of the buttons.

name string

Field name.

options IEnumerable<(string Value, PdfRectangle Rect)>

Export value and rectangle of every button.

selected string

Initially selected export value.

border PdfColor?

Border color (default black).

background PdfColor?

Background color (default none, so the page content below stays visible).

borderWidth double

Border width in points; 0 = no border.

Returns

PdfRadioButtonGroup

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

page PdfPage
name string
rect PdfRectangle

Returns

PdfSignatureField

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

page PdfPage
name string
rect PdfRectangle
value string
fontSize double
multiline bool
border PdfColor?
background PdfColor?
borderWidth double

Returns

PdfTextField

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

pdfFileName string

Optional 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

pdfFileName string

Optional file name of the PDF the data belongs to (<f href>).

Returns

string

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

fields IEnumerable<PdfFormField>

GetField(string)

Returns the field with the given fully qualified name, or null.

public PdfFormField? GetField(string fullName)

Parameters

fullName string

Returns

PdfFormField

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

fullName string

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

IReadOnlyDictionary<string, string>

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

fdf byte[]

Returns

FormDataImportResult

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

xfdf Stream

Returns

FormDataImportResult

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

xfdf string

Returns

FormDataImportResult

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

field PdfFormField

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)

Parameters

fullName string
value string