Skip to content
DemoFAQ

PDF Generation Template Editor

Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.

View on GitHub
Flutter Guides Access forms

Access Forms ​

The steps to retrieve the form field list and form field objects are as follows:

  1. Obtain the document object (either from the CPDFReaderWidgetcontroller or a CPDFDocument instance).
  2. Get the page object.
  3. Retrieve the list of form fields from each page.

Here’s the corresponding code:

Using CPDFReaderWidget:

dart
CPDFReaderWidgetController? _controller;
// Initialize CPDFReaderWidget and get the controller in the onCreated callback
CPDFReaderWidget(
  document: documentPath,
  configuration: CPDFConfiguration(),
  onCreated: (controller) {
    setState(() {
      this._controller = controller;
    });
  },
)
// Retrieve all form fields in the document
List<CPDFWidget> widgets = [];
int pageCount = await _controller.document.getPageCount();
for (int i = 0; i < pageCount; i++) {
  CPDFPage page = _controller.document.pageAtIndex(i);
  var pageWidgets = await page.getWidgets();
  widgets.addAll(pageWidgets);
}

Using CPDFDocument:

dart
// Create and open the document
CPDFDocument document = await CPDFDocument.createInstance();
var error = await document.open(pdfFilePath);
if (error == CPDFDocumentError.success) {
  // Retrieve all form fields in the document
  List<CPDFWidget> widgets = [];
  int pageCount = await document.getPageCount();
  for (int i = 0; i < pageCount; i++) {
    CPDFPage page = document.pageAtIndex(i);
    var pageWidgets = await page.getWidgets();
    widgets.addAll(pageWidgets);
  }
}

Read Signature Field Status ​

Starting with 3.2.0, CPDFSignatureWidget.isSigned indicates whether a field contains a digital signature:

dart
final widgets = await document.pageAtIndex(0).getWidgets();
for (final signature in widgets.whereType<CPDFSignatureWidget>()) {
  print('${signature.title}: ${signature.isSigned}');
}

Import package:compdfkit_flutter/annotation/form/cpdf_signature_widget.dart before using this type. isSigned does not indicate successful verification. See Read and Verify Digital Signatures for integrity and certificate trust checks.