Java Convert PDF to PDFA
Tags: pdf, pdfa, java, code
Published: 2023-07-12 03:15:37

PDF/A is a variation of the PDF format that ensures a document can be reproduced exactly the same way, regardless of what software is used. Basically, all of the information necessary for displaying the document and its elements in the same manner is embedded in the file—which ensure your documents safe, accessible, and secure for the long term. This article will demonstrate how to convert PDF to PDF/A. [Spire.PDF for java](https://www.e-iceblue.com/Introduce/pdf-for-java.html) supports to convert PDF to PdfA1A, PDF to PdfA1B, PDF to PdfA2A, PDF to PdfA2B, PDF to PdfA3A, and PDF to PdfA3B. 

###Part 1: Understanding the Spire.PDF Library

To convert PDF to PDF/A, we will make use of the Spire.PDF library. Spire.PDF for Java is a PDF API that enables Java applications to read, write and save PDF documents without installing Adobe Acrobat on the machine.

Before we can use the Spire.PDF to save PDF as PDF/A, we need to add its dependency to our Java project. We can do this by adding the following dependency to our Maven project:

```java
<repositories>
    <repository>
        <id>com.e-iceblue</id>
        <name>e-iceblue</name>
        <url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.pdf</artifactId>
        <version>9.7.0</version>
    </dependency>
</dependencies>
```
###Part 2: Writing the Java Code

Once we have added the Spire.PDF for java dependency to our project, we can start writing the Java code to save PDF as PDF/A.
Create a PdfStandardsConverter instance, and pass in a sample PDF file as a parameter.

- Convert the sample file to PdfA1A conformance level using PdfStandardsConverter.toPdfA1A() method.
- Convert the sample file to PdfA1B conformance level using PdfStandardsConverter. toPdfA1B() method.
- Convert the sample file to PdfA2A conformance level using PdfStandardsConverter. toPdfA2A() method.
- Convert the sample file to PdfA2B conformance level using PdfStandardsConverter. toPdfA2B() method.
- Convert the sample file to PdfA3A conformance level using PdfStandardsConverter. toPdfA3A() method.
- Convert the sample file to PdfA3B conformance level using PdfStandardsConverter. toPdfA3B() method.

```java
import com.spire.pdf.conversion.PdfStandardsConverter;

public class ConvertPdfToPdfA {
    public static void main(String[] args) {

        //Create a PdfStandardsConverter instance, and pass in a sample file as a parameter
        PdfStandardsConverter converter = new PdfStandardsConverter("sample.pdf");

        //Convert to PdfA1A
        converter.toPdfA1A("output/ToPdfA1A.pdf");

        //Convert to PdfA1B
        converter.toPdfA1B("output/ToPdfA1B.pdf");

        //Convert to PdfA2A
        converter.toPdfA2A( "output/ToPdfA2A.pdf");

        //Convert to PdfA2B
        converter.toPdfA2B("output/ToPdfA2B.pdf");

        //Convert to PdfA3A
        converter.toPdfA3A("output/ToPdfA3A.pdf");

        //Convert to PdfA3B
        converter.toPdfA3B("output/ToPdfA3B.pdf");
    }
}
```
###Conclusion

In conclusion, it is easy to save PDF to PDF/A by using Spire.PDF for java. Spire.PDF also supports to convert PDF to other formats, such as [PDF to image](https://www.e-iceblue.com/Tutorials/JAVA/Spire.PDF-for-JAVA/Program-Guide/Conversion/Convert-PDF-to-Image-in-Java.html), [PDF to Word](https://www.e-iceblue.com/Tutorials/Java/Spire.PDF-for-Java/Program-Guide/Conversion/Convert-PDF-to-Word-in-Java.html), [PDF to Excel](https://www.e-iceblue.com/Tutorials/Java/Spire.PDF-for-Java/Program-Guide/Conversion/Convert-PDF-to-Excel-in-Java.html), [PDF to PowerPoint](https://www.e-iceblue.com/Tutorials/Java/Spire.PDF-for-Java/Program-Guide/Conversion/Java-Convert-PDF-to-PowerPoint-Presentation.html) and [PDF to SVG](https://www.e-iceblue.com/Tutorials/Java/Spire.PDF-for-Java/Program-Guide/Conversion/Convert-PDF-to-SVG-in-Java.html).