Unlock the Power of Free Spire.PDF for Java: Effortlessly Convert XPS to PDF for Free!

Java programmers often find themselves in need of converting XPS files to PDF format, but the process can be cumbersome and expensive. However, with the power of Java, this task can be achieved quickly and efficiently – without costing a penny! The purpose of today's article is to show you how to programmatically convert XPS to PDF. For your reference, I have attached Java code with the ideas and methods I have sorted out.

How to install Free Spire.PDF for Java

To get started with Free Spire.PDF for Java, you will first need to download the latest version of the library from their official website.

Convert XPS to PDF for Free

The following are steps to convert XPS to PDF.

  • Create a PdfDocument instance.

  • Load a XPS file document using PdfDocument.loadFromFile() method.

  • Save the document as PDF using PdfDocument.saveToFile() method.

Here is an example Java code snippet that demonstrates how to convert a PDF file to an XPS file using Free Spire.PDF for Java:

import com.spire.pdf.*;

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

        //Create a PdfDocument instance
        PdfDocument pdf = new PdfDocument();

        //Load a XPS file
        pdf.loadFromXPS("C:\\Users\\Administrator\\Desktop\\sample.xps");

        //Save to PDF
        pdf.saveToFile("toPDF.pdf", FileFormat.PDF);
        pdf.close();
    }
}

Conclusion:

In addition to XPS to PDF conversion, Spire.PDF for Java offers many other useful features. For example, you can use Spire.PDF to insert text/image watermark to the PDF, add/update/delete PDF bookmarks. You can also use it to add images, text, and graphics to your PDF files. Additionally, Spire.PDF for Java can be applied easily to convert PDF to Word, and PDF to PDF/A in high quality. In short, Spire.PDF for Java is a useful tool to convert PDF to Word. With the additional features it offers, it is a complete solution for all your PDF file needs.