Knowledgebase (2300)
PDF (Portable Document Format) and XPS (XML Paper Specification) are two commonly used document formats for sharing and printing documents. While PDF is widely known and supported, XPS is a Microsoft-developed format that has gained popularity due to its superior graphics rendering capabilities. In this article, we will demonstrate how to use Spire.PDF for Java to convert PDF to XPS and XPS to PDF in high quality.
Install Spire.PDF for Java
First of all, you're required to add the Spire.Pdf.jar file as a dependency in your Java program. The JAR file can be downloaded from this link. If you use Maven, you can easily import the JAR file in your application by adding the following code to your project's pom.xml file.
<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>11.11.11</version>
</dependency>
</dependencies>
Convert PDF to XPS in Java
Spire.PDF for Java has a powerful conversion feature, which can convert PDF to XPS in just three steps. The detailed steps are as follows:
- Create a PdfDocument instance.
- Load a PDF sample document using PdfDocument.loadFromFile() method.
- Save the document as XPS using PdfDocument.saveToFile() method.
- Java
import com.spire.pdf.*;
public class PDFtoXPS {
public static void main(String[] args) {
//Create a PdfDocument instance
PdfDocument pdf = new PdfDocument();
//Load the PDF file
pdf.loadFromFile("C:\\Users\\Administrator\\Desktop\\Input.pdf.pdf");
//Save to XPS
pdf.saveToFile("ToXPS.xps", FileFormat.XPS);
pdf.close();
}
}

Convert XPS to PDF in Java
The PdfDocument.saveToFile() method provided by Spire.PDF for Java enables the conversion of a XPS file into a PDF document. 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.
- 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();
}
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
SVG, short for scalable vector graphics, is a vector image format based on XML for two-dimensional graphics. Vector image files, like SVG and PDF files, are very similar. They can display text, images, and other elements in the same appearance and keep the definition no matter how you zoom them. And because of their similarity, PDF files can be converted to SVG files almost losslessly. This article shows an easy method to convert PDF files to SVG files using Spire.PDF for Java.
- Convert Each Page of a PDF File to an SVG File
- Convert All the Pages of a PDF File to a Single SVG File
Install Spire.PDF for Java
First, you're required to add the Spire.Pdf.jar file as a dependency in your Java program. The JAR file can be downloaded from this link. If you use Maven, you can easily import the JAR file in your application by adding the following code to your project's pom.xml file.
<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>11.11.11</version>
</dependency>
</dependencies>
Convert Each Page of a PDF File to an SVG File
The detailed steps are as follows:
- Create an object of PdfDocument class.
- Load a PDF document from disk using PdfDocument.loadFromFile() method.
- Convert the document to SVG file and save it using PdfDocument.saveToFile() method.
- Java
import com.spire.pdf.*;
public class PDFToSVG {
public static void main(String[] args) {
//Create an object of Document class
PdfDocument pdf = new PdfDocument();
//Load a PDF document from disk
pdf.loadFromFile("D:/Samples/Sample.pdf");
//Convert the document to SVG and Save it
pdf.saveToFile("D:/javaOutput/PDFToSVG.svg", FileFormat.SVG);
}
}

Convert All the Pages of a PDF File to a Single SVG File
The detailed steps are as follows:
- Create an object of PdfDocument class.
- Load a PDF document from disk using PdfDocument.loadFromFile() method.
- Change the conversion settings to convert the PDF file to a single SVG file using PdfDocument.getConvertOptions().setOutputToOneSvg() method.
- Convert the document to SVG file and save it using PdfDocument.saveToFile() method.
- Java
import com.spire.pdf.*;
public class PDFToSVG {
public static void main(String[] args) {
//Create an object of Document class
PdfDocument pdf = new PdfDocument();
//Load a PDF document from disk
pdf.loadFromFile("D:/Samples/Sample.pdf");
//Change the conversion settings to convert the PDF file to a single SVG file
pdf.getConvertOptions().setOutputToOneSvg(true);
//Convert the document to SVG and Save it
pdf.saveToFile("D:/javaOutput/PDFToSVG.svg", FileFormat.SVG);
}
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
PDF file format makes the presentation of documents consistent across devices. However, when you need to put PDF documents on web pages, it's better to convert them to HTML files. In this way, all the content of your document can be displayed in the browser directly, with no need for downloading files. And the loading of large PDF documents takes a long time, while HTML files can be rendered in the browser very quickly. In addition, compared to PDF files, it is much easier for search engines to crawl HTML web pages to get information, which will give your website more exposure. This article will show how to convert PDF documents into HTML files in Java using Spire.PDF for Java.
- Convert a PDF document to an HTML file in Java
- Convert a PDF document to an HTML file with SVG Embedded
- Convert a PDF document to HTML Stream in Java
Install Spire.PDF for Java
First of all, you're required to add the Spire.Pdf.jar file as a dependency in your Java program. The JAR file can be downloaded from this link. If you use Maven, you can easily import the JAR file in your application by adding the following code to your project's pom.xml file.
<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>11.11.11</version>
</dependency>
</dependencies>
Convert a PDF document to an HTML file in Java
The conversion from a PDF document to an HTML file can be directly done by loading a PDF document and saving it as an HTML file using PdfDocument.saveToFile(String filename, FileFormat.HTML) method provided by Spire.PDF for Java. The detailed steps are as follows.
- Create an object of PdfDocument.
- Load a PDF file using PdfDocument.loadFromFile() method.
- Save the PDF file as an HTML file using PdfDocument.saveToFle() method.
- Java
Java
import com.spire.pdf.*;
public class convertPDFToHTML {
public static void main(String[] args) {
//Create an object of PdfDocument
PdfDocument pdf = new PdfDocument();
//Load a PDF file
pdf.loadFromFile("C:/Guide to a Foreign Past.pdf");
//Save the PDF file as an HTML file
pdf.saveToFile("PDFToHTML.html",FileFormat.HTML);
pdf.close();
}
}
Convert a PDF document to an HTML file with SVG Embedded
Spire.PDF for Java also provides the PdfDocument.getConvertOptions().setPdfToHtmlOptions(true) method to enable embedding SVG while converting. The detailed steps for converting a PDF file to an HTML file with SVG embedded are as follows.
- Create an object of PdfDocument.
- Load a PDF file using PdfDocument.loadFromFile() method.
- Enable embedding SVG using PdfDocument.getConvertOptions().setPdfToHtmlOptions(true) method.
- Save the PDF file as an HTML file using PdfDocument.saveToFle() method.
- Java
import com.spire.pdf.*;
public class convertPDFToHTMLEmbeddingSVG {
public static void main(String[] args) {
//Create an object of PdfDocument
PdfDocument doc = new PdfDocument();
//Load a PDF file
doc.loadFromFile("C:/Guide to a Foreign Past.pdf");
//Set embedding SVG
doc.getConvertOptions().setPdfToHtmlOptions(true);
//Save the PDF file as an HTML file
doc.saveToFile("PDFToHTMLEmbeddingSVG.html", FileFormat.HTML);
doc.close();
}
}
Convert a PDF document to HTML Stream in Java
Spire.PDF for Java also supports converting PDF documents to HTML stream. The detailed steps are as follows.
- Create an object of PdfDocument.
- Load a PDF file using PdfDocument.loadFromFile() method.
- Save the PDF file as HTML stream using PdfDocument.saveToStream() method.
- Java
import com.spire.pdf.*;
import java.io.*;
public class convertPDFToHTMLStream {
public static void main(String[] args) throws FileNotFoundException {
//Create an object of PdfDocument
PdfDocument pdf = new PdfDocument();
//Load a PDF file
pdf.loadFromFile("C:/Guide to a Foreign Past.pdf");
//Save the PDF file as HTML stream
File outFile = new File("PDFToHTMLStream.html");
OutputStream outputStream = new FileOutputStream(outFile);
pdf.saveToStream(outputStream, FileFormat.HTML);
pdf.close();
}
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.