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 Pdf standard conversion

PDF Standard Detection and Conversion ​

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.

dart
import 'package:compdfkit_flutter/compdfkit.dart';

Read the Standard Type ​

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.

Convert to a Selected Standard ​

dart
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:

StandardCPDFPdfStandardType
PDF/A-1pdfA1a, pdfA1b
PDF/A-2pdfA2a, pdfA2u, pdfA2b
PDF/A-3pdfA3a, pdfA3u, pdfA3b
PDF/XpdfX1a, pdfX3, pdfX4
PDF/EpdfE1
PDF/UApdfUA1
PDF/VTpdfVT1, pdfVT2

fontSubset controls font subsetting in the output and defaults to true.

Output and Saving ​

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.

Handle Failures ​

Exception codeAction
INVALID_OUTPUT_PATHCheck the directory, write permission, and source and output paths
DOCUMENT_INVALIDReopen a valid document
ENCRYPTED_DOCUMENT_NOT_CONVERTIBLEWrite and open an unencrypted copy first
PDF_STANDARD_CONVERT_FAILEDRead the error message and check whether the source can be converted
PDF_STANDARD_SAVE_FAILEDCheck available storage and write permission
PDF_STANDARD_RESTORE_FAILEDOn 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