PDF Generation Template Editor
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
Starting with 3.2.0, ComPDF Flutter SDK supports certificate-based signing of PDF signature fields. A digital signature provides document integrity and signer information; an image signature only adds a signature image.
Prepare the certificate path, password, and a writable output path, then open the target PDF. In these examples, document is the current CPDFDocument.
import 'package:compdfkit_flutter/compdfkit.dart';
import 'package:compdfkit_flutter/annotation/form/cpdf_signature_widget.dart';final widgets = await document.pageAtIndex(0).getWidgets();
final unsignedFields = widgets
.whereType<CPDFSignatureWidget>()
.where((field) => !field.isSigned)
.toList();isSigned indicates whether the field already contains a digital signature. If the document has no signature field, create a form field first and read it again.
The field passed to the signing API must belong to the current document and have a valid native uuid. Use a field returned by getWidgets() or a reader callback. A newly constructed Dart object alone cannot be used directly for signing.
if (unsignedFields.isNotEmpty) {
final success = await document.writeSignature(
unsignedFields.first,
'/path/to/signed.pdf',
CPDFDigitalSignatureConfig(
certificatePath: certificatePath,
password: certificatePassword,
reason: 'Approved',
location: 'Office',
permissions: CPDFSignaturePermission.fillAndSign,
appearance: const CPDFDigitalSignatureAppearance(
text: 'Signed by Document Signer',
content: 'Approved',
drawLogo: false,
),
),
);
if (success) {
await document.open('/path/to/signed.pdf');
}
}The signature is written to a new file. Use an output path different from the source, with an existing parent directory. After success, open the output file to view or verify the signature.
| Setting | Purpose |
|---|---|
certificatePath, password | PKCS#12 certificate and password |
name, reason, location | Signer name, signing reason, and location |
permissions | Document changes allowed by the signature |
appearance | Signature text, colors, images, and layout |
timestampServerUrl | Signature timestamp service; see Timestamps and Long-Term Validation |
CPDFSignaturePermission defines the changes allowed after signing:
| Value | Description |
|---|---|
forbidChange | Disallow changes to the document |
fillAndSign | Allow form filling and signing |
annotationFillAndSign | Allow annotation, form filling, and signing |
permissions defaults to fillAndSign. It describes modification permissions associated with the signature, separately from document opening passwords and encryption permissions.
Configure the appearance with text, content, textColor, contentColor, imagePath, logoPath, drawLogo, drawOnlyContent, and contentAlignLeft. Image settings use local file paths.
Invalid arguments may throw ArgumentError. Native signing failures may return false or throw a platform exception. Open the output only after confirming success. See Read and Verify Digital Signatures.