Convert PDF to PDF/A, PDF/E, and PDF/X in Java
Contents
[
Hide
]
Aspose.PDF for Java can validate and convert standard PDF files into archival and exchange-oriented PDF standards.
Convert PDF to PDF/A
Use this example when a standard PDF should be converted into a PDF/A-compliant archival document.
- Open the source PDF in a
Documentinstance. - Call
document.convert(...)withPdfFormatPDF_A_1BandConvertErrorActionDelete. - Write the validation log to a sidecar XML file so compliance issues are recorded during conversion.
- Save the validated PDF/A output.
public static void convertPdfToPdfA(Path inputFile, Path outputFile) {
try (Document document = new Document(inputFile.toString())) {
document.convert(logFile(outputFile, "-log.xml").toString(), PdfFormat.PDF_A_1B, ConvertErrorAction.Delete);
document.save(outputFile.toString());
}
}
Convert PDF to PDF/E
Use this example when a PDF should be converted into the engineering-oriented PDF/E standard.
- Create
PdfFormatConversionOptionsforPdfFormatPDF_E_1and the desired log-file path. - Open the source PDF in a
Documentinstance. - Call
document.convert(options)so the compliance conversion is executed with the prepared options object. - Save the resulting compliant PDF file.
public static void convertPdfToPdfE(Path inputFile, Path outputFile) {
PdfFormatConversionOptions options = new PdfFormatConversionOptions(
logFile(outputFile, "-log.xml").toString(), PdfFormat.PDF_E_1, ConvertErrorAction.Delete);
try (Document document = new Document(inputFile.toString())) {
document.convert(options);
document.save(outputFile.toString());
}
}
Convert PDF to PDF/X
Use this example when a PDF should be converted into the print-oriented PDF/X standard.
- Create
PdfFormatConversionOptionsforPdfFormatPDF_X_4and the desired log-file path. - Configure an
OutputIntentsuch asFOGRA39so the print-target color profile is embedded into the conversion settings. - Open the source PDF in a
Documentinstance and calldocument.convert(options). - Save the converted PDF/X output.
public static void convertPdfToPdfX(Path inputFile, Path outputFile) {
PdfFormatConversionOptions options = new PdfFormatConversionOptions(
logFile(outputFile, "-log.xml").toString(), PdfFormat.PDF_X_4, ConvertErrorAction.Delete);
options.setOutputIntent(new OutputIntent("FOGRA39"));
try (Document document = new Document(inputFile.toString())) {
document.convert(options);
document.save(outputFile.toString());
}
}