Class PdfForm
Reads and fills the interactive form (AcroForm) of a PDF document. GetFields(string, CancellationToken) reports every form field with its name, kind, current value, options, and flags; Fill(string, PdfFormFillRequest, CancellationToken) writes values into the fields through the PDF form engine, which commits each value and regenerates the widget's appearance so the filled document renders correctly everywhere.
public static class PdfForm
- Inheritance
-
PdfForm
- Inherited Members
Examples
Example 1: Discover the fields of a form.
using LMKit.Document.Pdf;
PdfFormSnapshot snapshot = PdfForm.GetFields("registration.pdf");
foreach (PdfFormFieldInfo field in snapshot.Fields)
{
Console.WriteLine($"{field.Name} ({field.Kind}): '{field.Value}'");
}
Example 2: Fill two fields and flatten the result.
using LMKit.Document.Pdf;
var request = new PdfFormFillRequest { Flatten = true };
request.Values.Add(new PdfFormFieldValue("full_name", "Marion Delacroix"));
request.Values.Add(new PdfFormFieldValue("subscribe", "true"));
PdfFormFillReport report = PdfForm.FillToFile("registration.pdf", "registration_filled.pdf", request);
Console.WriteLine($"Set {report.FieldsSet}, skipped {report.FieldsSkipped}");
Remarks
Field addressing. Values address fields by their exact name as reported by GetFields(string, CancellationToken). A value naming an unknown or read-only field is skipped and explained in the report's Issues; it never throws.
Flattening. When Flatten is set, the filled values are baked into the static page content and the editable fields are removed from the output.
Input modes. File paths, raw bytes, and pre-built Attachment objects are accepted, in synchronous and asynchronous forms. A document without an interactive form yields an empty snapshot from GetFields(string, CancellationToken), and a fill against it reports every value as skipped.
Methods
- Fill(Attachment, PdfFormFillRequest, CancellationToken)
Fills the form of the PDF carried by
attachmentand returns the filled bytes together with the report.
- Fill(byte[], PdfFormFillRequest, CancellationToken)
Fills the form of in-memory PDF bytes and returns the filled bytes together with the report.
- Fill(string, PdfFormFillRequest, CancellationToken)
Fills the form of the PDF at
inputPathand returns the filled bytes together with the report.
- FillAsync(Attachment, PdfFormFillRequest, CancellationToken)
Asynchronously fills the form of the PDF carried by
attachmentand returns the filled bytes together with the report.
- FillAsync(byte[], PdfFormFillRequest, CancellationToken)
Asynchronously fills the form of in-memory PDF bytes and returns the filled bytes together with the report.
- FillAsync(string, PdfFormFillRequest, CancellationToken)
Asynchronously fills the form of the PDF at
inputPathand returns the filled bytes together with the report.
- FillToFile(string, string, PdfFormFillRequest, CancellationToken)
Fills the form of the PDF at
inputPathand writes the result tooutputPath.
- FillToFileAsync(string, string, PdfFormFillRequest, CancellationToken)
Asynchronously fills the form of the PDF at
inputPathand writes the result tooutputPath.
- GetFields(Attachment, CancellationToken)
Reads the form fields of the PDF carried by
attachment.
- GetFields(byte[], CancellationToken)
Reads the form fields of in-memory PDF bytes.
- GetFields(string, CancellationToken)
Reads the form fields of the PDF at
inputPath.
- GetFieldsAsync(Attachment, CancellationToken)
Asynchronously reads the form fields of the PDF carried by
attachment.
- GetFieldsAsync(byte[], CancellationToken)
Asynchronously reads the form fields of in-memory PDF bytes.
- GetFieldsAsync(string, CancellationToken)
Asynchronously reads the form fields of the PDF at
inputPath.