Java/ Change PDF Version

Andrew Wilson
1 min readJan 17, 2022

In our daily work, we may find that some devices have strict requirements on the PDF version. Therefore, we need to convert PDF file between different versions for compatibility purpose. This article will show how to programmatically change the PDF version by using Free Spire.PDF for Java (Supports the PDF versions from 1.0 to 1.7).

Installation
Method 1: Download the Free Spire.PDF for Java and unzip it.Then add the Spire.Pdf.jar file to your project as dependency.

Method 2: You can also add the jar dependency to maven project by adding the following configurations to the pom.xml.

<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>http://repo.e-iceblue.com/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.pdf.free</artifactId>
<version>4.4.1</version>
</dependency>
</dependencies>

Sample Code:

The detailed steps are as follows:

  1. Create a PdfDocument object.
  2. Load a sample PDF file using PdfDocument.loadFromFile() method.
  3. Change the PDF version using PdfDocument.getFileInfo().setVersion() method.
  4. Save the result file using PdfDocument.saveToFile() method.
package com.spire.pdf;

public class ChangePdfVersion {

public static void main(String[] args) {

//Create a PdfDocument object
PdfDocument document = new PdfDocument();

//Load a sample PDF file
document.loadFromFile("test.pdf");

//Change the PDF version to 1.6
document.getFileInfo().setVersion(PdfVersion.Version_1_6);

//Save to file
document.saveToFile("PdfVersion.pdf", FileFormat.PDF);
document.close();
}
}

--

--

Andrew Wilson

Explore C#, Java and Python solutions for processing Word/Excel/PowerPoint/PDF files.