Skip to content
DemoSampleAPI ReferenceFAQ

PDF Generation Template Editor

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

View on GitHub
Android Guides Pdfa

PDF Standard Conversion ​

Use CPDFDocument.convertType() to convert an open PDF to a target standard type. Conversion adjusts document content or resources; success depends on the source and target. Check the return value and save the output.

Select a Target Type ​

TypePDFDocumentType values
PDF/A-1PDFTypeA1a, PDFTypeA1b
PDF/A-2PDFTypeA2a, PDFTypeA2u, PDFTypeA2b
PDF/A-3PDFTypeA3a, PDFTypeA3u, PDFTypeA3b
PDF/XPDFTypeX1a, PDFTypeX3, PDFTypeX4
PDF/EPDFTypeE1, PDFTypeE2
PDF/VTPDFTypeVT1, PDFTypeVT2
PDF/UAPDFTypeUA1

The current enum does not include PDF/A-4. Do not infer support for types absent from the enum.

Convert, Save, and Inspect ​

This example converts an open document to PDF/A-2b. outputPath is a writable new file path whose parent directory exists. Run the operation on a background thread.

java
CPDFDocument.PDFDocumentType target = CPDFDocument.PDFDocumentType.PDFTypeA2b;
if (document.convertType(target)) {
    try {
        boolean saved = document.saveAs(outputPath, false);
        if (saved) {
            CPDFDocument output = new CPDFDocument(context);
            try {
                if (output.open(outputPath)
                        == CPDFDocument.PDFDocumentError.PDFDocumentErrorSuccess) {
                    boolean matches = output.getType() == target;
                    // Use matches to inspect the saved document type.
                }
            } finally {
                output.close();
            }
        }
    } catch (CPDFDocumentException e) {
        // Conversion completed but saving failed. Retry or report the error as appropriate.
    }
} else {
    // Conversion failed; do not proceed as though it succeeded.
}
kotlin
val target = CPDFDocument.PDFDocumentType.PDFTypeA2b
if (document.convertType(target)) {
    try {
        if (document.saveAs(outputPath, false)) {
            val output = CPDFDocument(context)
            try {
                if (output.open(outputPath) ==
                    CPDFDocument.PDFDocumentError.PDFDocumentErrorSuccess) {
                    val matches = output.type == target
                    // Use matches to inspect the saved document type.
                }
            } finally {
                output.close()
            }
        }
    } catch (e: CPDFDocumentException) {
        // Handle save failure.
    }
} else {
    // Handle conversion failure.
}

The example uses CPDFDocument from com.compdfkit.core.document and CPDFDocumentException from com.compdfkit.core.common.

Usage Notes ​

  • For encrypted input, first remove encryption with saveAs(path, true), then reopen the decrypted file before conversion.
  • convertType() changes the document in memory. Save successful changes and close instances no longer needed.
  • getType() checks the type recognized by the SDK and does not replace independent conformance validation. Validate separately when required for delivery.

For other format conversions, see Conversion SDK.