pdf_acroform 0.1.0
pdf_acroform: ^0.1.0 copied to clipboard
A Dart/Flutter package for parsing PDF AcroForm fields and displaying interactive form overlays. Extract form metadata, pre-filled values, and render editable fields on top of PDF documents.
pdf_acroform #
A Dart/Flutter package for parsing PDF AcroForm fields and displaying interactive form overlays.
Features #
- Parse AcroForm fields from PDF documents
- Extract field metadata: name, type, position, default values
- Support for text fields, checkboxes, dropdowns, and more
- Field properties: multiline, read-only, max length, text alignment
- Flutter widget to display PDF with editable form overlays
- Pure Dart parser (works without Flutter)
Installation #
Add to your pubspec.yaml:
dependencies:
pdf_acroform:
git:
url: https://github.com/alpaga-dev/pdf_acroform.git
Usage #
Parsing PDF form fields (Dart) #
import 'package:pdf_acroform/pdf_acroform.dart';
// Parse a PDF file
final parser = await AcroFormParser.fromFile('form.pdf');
final fields = await parser.extractFields();
// List all fields
for (final field in fields) {
print('${field.name}: ${field.type}');
}
// Extract pre-filled values as a Map
final formData = fields.extractFormData();
print(formData); // {'firstName': 'John', 'newsletter': true, ...}
// Filter fields
final textFields = fields.ofType(PdfFieldType.text);
final page1Fields = fields.forPage(0);
Displaying PDF with form overlays (Flutter) #
import 'package:pdf_acroform/pdf_acroform.dart';
import 'package:pdf_acroform/pdf_acroform_viewer.dart';
class MyFormScreen extends StatefulWidget {
@override
State<MyFormScreen> createState() => _MyFormScreenState();
}
class _MyFormScreenState extends State<MyFormScreen> {
List<PdfFormField>? _fields;
Map<String, dynamic> _formData = {};
@override
void initState() {
super.initState();
_loadPdf();
}
Future<void> _loadPdf() async {
final parser = await AcroFormParser.fromFile('form.pdf');
final fields = await parser.extractFields();
setState(() {
_fields = fields;
_formData = fields.extractFormData();
});
}
@override
Widget build(BuildContext context) {
if (_fields == null) {
return const Center(child: CircularProgressIndicator());
}
return PdfFormViewer(
pdfPath: 'form.pdf',
fields: _fields!,
formData: _formData,
onFieldChanged: (name, value) {
setState(() => _formData[name] = value);
},
);
}
}
Supported field types #
| Type | Description |
|---|---|
text |
Single or multiline text input |
button |
Checkbox or radio button |
choice |
Dropdown or list selection |
signature |
Signature field (detected but not editable) |
Field properties #
The parser extracts the following properties when available:
name- Fully qualified field nametype- Field type (text, button, choice, signature)rect- Position and dimensions on the pagepageIndex- Zero-based page numberdefaultValue- Pre-filled valueisMultiline- Whether text field supports multiple linesisReadOnly- Whether field is editablemaxLength- Maximum character countalignment- Text alignment (left, center, right)options- Available choices for dropdown fields
Example app #
See the example/ directory for a complete demo application.
cd example
flutter run
License #
MIT