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 reading a document's declared PDF standard type and converting it to a selected standard as a copy.
In these examples, document is an opened CPDFDocument.
import 'package:compdfkit_flutter/compdfkit.dart';final type = await document.getPdfStandardType();
print(type.value);This API reads the document's declared standard type. It is not a complete conformance validation.
try {
final success = await document.convertToPdfStandard(
'/path/to/output-pdfa2b.pdf',
CPDFPdfStandardType.pdfA2b,
fontSubset: true,
);
if (success) {
print('Converted copy saved.');
}
} on CPDFPdfStandardException catch (error) {
print('${error.code}: ${error.message}');
}The following conversion targets are available on Android and iOS:
| Standard | CPDFPdfStandardType |
|---|---|
| PDF/A-1 | pdfA1a, pdfA1b |
| PDF/A-2 | pdfA2a, pdfA2u, pdfA2b |
| PDF/A-3 | pdfA3a, pdfA3u, pdfA3b |
| PDF/X | pdfX1a, pdfX3, pdfX4 |
| PDF/E | pdfE1 |
| PDF/UA | pdfUA1 |
| PDF/VT | pdfVT1, pdfVT2 |
fontSubset controls font subsetting in the output and defaults to true.
The output path must be writable, have an existing parent directory, and differ from the source path. An existing output file is overwritten. After conversion succeeds, open the output copy to view the result.
The output includes unsaved changes from the current document. Android reloads the current document from its source after conversion, while iOS converts a copy. Save first to retain changes in the current document. For an encrypted document, use saveAs() to write an unencrypted copy and open that copy before converting.
| Exception code | Action |
|---|---|
INVALID_OUTPUT_PATH | Check the directory, write permission, and source and output paths |
DOCUMENT_INVALID | Reopen a valid document |
ENCRYPTED_DOCUMENT_NOT_CONVERTIBLE | Write and open an unencrypted copy first |
PDF_STANDARD_CONVERT_FAILED | Read the error message and check whether the source can be converted |
PDF_STANDARD_SAVE_FAILED | Check available storage and write permission |
PDF_STANDARD_RESTORE_FAILED | On Android, a copy was written but the current document could not be restored. Close and reopen the source; do not save the document in memory |