Convert PDF to PDF/A in Java

This article demonstrates how to convert PDF to PDF/A using Spire.PDF for Java.

import com.spire.pdf.PdfConformanceLevel;
import com.spire.pdf.PdfDocument;
import com.spire.pdf.PdfNewDocument;
import com.spire.pdf.PdfPageBase;
import com.spire.pdf.graphics.PdfMargins;

import java.awt.geom.Dimension2D;

public class PDFToPDFA {
    public static void main(String[] args)
    {
        //Load pdf file
        PdfDocument document = new PdfDocument();
        document.loadFromFile("Sales Report.pdf");

        //Convert to Pdf_A_1_B
        PdfNewDocument newDoc = new PdfNewDocument();
        newDoc.setConformance(PdfConformanceLevel.Pdf_A_1_B);
        for (PdfPageBase page : (Iterable) document.getPages()) {
            Dimension2D size = page.getSize();
            PdfPageBase p = newDoc.getPages().add(size, new PdfMargins(0));
            page.createTemplate().draw(p, 0, 0);
        }

        //Save the file
        newDoc.save("Output.pdf");
        newDoc.close();
    }
}

Output:

Convert PDF to PDF/A in Java