XPS (XML Paper Specification) is a fixed-layout document format designed to preserve document fidelity, providing device-independent document appearance. This article will introduce how to convert PDF to XPS and XPS to PDF in high quality using Free Spire.PDF for Java.
Import JAR Dependency
Method 1: You can download the free library and unzip it. Then add the Spire.Pdf.jar file to your project as dependency.
Method 2: Or you can directly 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>
Convert PDF to XPS
The PdfDocument.saveToFile() method offered by Free Spire.PDF for Java allows you to save the input PDF document to other file Formats. All you need to do is load the PDF document using PdfDocument.loadFromFile() method and then save it to .xps file format.
import com.spire.pdf.*;
public class PDFtoXPS {
public static void main(String[] args) {
//Load the PDF file
PdfDocument pdf = new PdfDocument();
pdf.loadFromFile("sample2.pdf");
//Save to XPS
pdf.saveToFile("ToXPS.xps", FileFormat.XPS);
}
}
Convert XPS to PDF
import com.spire.pdf.*;
public class XPStoPDF{
public static void main(String[] args) {
//Load XPS
PdfDocument pdf = new PdfDocument();
pdf.loadFromXPS("ToXPS.xps");
//Save to PDF
pdf.saveToFile("toPDF.pdf", FileFormat.PDF);
}
}
Top comments (0)