XPS to PDF conversion in Java is essential for many enterprise workflows that need reliable, print‑ready documents. Conholdate.Total for Java is a powerful SDK that simplifies this task for Java developers. In this guide you will learn how to set up the library, run a complete conversion example, explore key options, and apply performance best practices.
How to Perform XPS to PDF Conversion in Java - Step by Step
Add Maven or Gradle Dependency: Include Conholdate.Total in your build file so the SDK classes are available.
<repositories> <repository> <id>conholdate-repo</id> <name>Conholdate Maven Repository</name> <url>https://repository.conholdate.com/repo/</url> </repository> </repositories> <dependency> <groupId>com.conholdate</groupId> <artifactId>conholdate-total</artifactId> <version>24.9</version> <type>pom</type> </dependency>Initialize the Converter: Load the XPS source using
XpsLoadOptions.LoadOptions loadOptions = new XpsLoadOptions(); try (Converter converter = new Converter("sample.xps", loadOptions)) { // conversion will be performed in the next step }Configure PDF Output: Set compliance, page size, orientation, and render mode via
PdfConvertOptions.PdfConvertOptions pdfOptions = new PdfConvertOptions(); pdfOptions.setCompliance(PdfConvertOptions.PdfCompliance.PDF_A_1B); pdfOptions.setPageSize(PdfPageSize.A4); pdfOptions.setPageOrientation(PdfPageOrientation.PORTRAIT); pdfOptions.setRenderMode(PdfRenderMode.FAST);Execute the Conversion: Call
converter.convertwith the output path and options.converter.convert("sample_converted.pdf", pdfOptions);Benchmark the Process: Record start and end times with
Instantto evaluate performance.Instant start = Instant.now(); // conversion code here Instant end = Instant.now(); System.out.println("Conversion completed in " + Duration.between(start, end).toMillis() + " ms");
For more details on each class, refer to the API reference.
XPS to PDF Sample - Complete Code Example
The following code demonstrates the core functionality of XPS to PDF conversion in Java using Conholdate.Total.
import com.groupdocs.conversion.Converter;
import com.groupdocs.conversion.options.load.LoadOptions;
import com.groupdocs.conversion.options.load.XpsLoadOptions;
import com.groupdocs.conversion.options.convert.PdfConvertOptions;
import com.groupdocs.conversion.options.convert.PdfConvertOptions.PdfCompliance;
import com.groupdocs.conversion.options.PdfPageSize;
import com.groupdocs.conversion.options.PdfPageOrientation;
import com.groupdocs.conversion.options.PdfRenderMode;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.time.Duration;
import java.time.Instant;
public class XpsToPdfDemo {
public static void main(String[] args) {
// Input XPS file and desired PDF output
String inputPath = "sample.xps";
String outputPath = "sample_converted.pdf";
// Start timing for benchmarking
Instant start = Instant.now();
// Load options (can be extended with password, etc.)
LoadOptions loadOptions = new XpsLoadOptions();
// Conversion options with PDF-specific settings
PdfConvertOptions pdfOptions = new PdfConvertOptions();
pdfOptions.setCompliance(PdfCompliance.PDF_A_1B); // PDF/A-1b compliance
pdfOptions.setPageSize(PdfPageSize.A4); // A4 page size
pdfOptions.setPageOrientation(PdfPageOrientation.PORTRAIT); // Portrait orientation
pdfOptions.setRenderMode(PdfRenderMode.FAST); // Faster rendering, lower memory
// Perform conversion inside try‑with‑resources to ensure proper cleanup
try (Converter converter = new Converter(inputPath, loadOptions)) {
converter.convert(outputPath, pdfOptions);
} catch (Exception e) {
System.err.println("XPS to PDF conversion failed: " + e.getMessage());
e.printStackTrace();
return;
}
// End timing and report duration
Instant end = Instant.now();
Duration elapsed = Duration.between(start, end);
System.out.println("Conversion completed in " + elapsed.toMillis() + " ms");
// Verify that the PDF file was created
if (Files.exists(Paths.get(outputPath))) {
System.out.println("PDF file successfully created at: " + outputPath);
} else {
System.err.println("PDF file was not created.");
}
}
}
Note: This code example demonstrates the core functionality. Before using it in your project, make sure to update any file paths and configuration values to match your actual environment, verify that all required dependencies are properly installed, and test thoroughly in your development environment. If you encounter any issues, please refer to the official documentation or reach out to the support team for assistance.
Conholdate.Total for Java - Prerequisites and Setup
To start converting XPS to PDF, you need Java 8 or higher and a valid Conholdate.Total license. Download the SDK from the download page. After adding the Maven dependency shown earlier, you can also use Gradle:
repositories {
maven {
url "https://repository.conholdate.com/repo/"
}
}
implementation 'com.conholdate:conholdate-total:24.9'
Make sure to place your license file in the application directory or set the license programmatically as described in the documentation.
Key Features of Conholdate.Total for Java for XPS to PDF
- PDF/A‑1b Compliance - Guarantees long‑term archiving compatibility.
- Fast Rendering Mode - Optimizes memory usage for large XPS files.
- Page Size and Orientation Control - Adjust output to A4, Letter, portrait, or landscape.
- Extensible Load Options - Future‑proof handling of password‑protected XPS files.
- Comprehensive API - Full access to conversion settings via the Java SDK.
For a deeper dive, see the official documentation.
Conversion Options: Tuning PDF Output
The PdfConvertOptions class offers several properties you can tweak:
- Compliance - Choose between PDF/A‑1b, PDF/A‑2b, etc. (already set in the sample).
- PageSize - Options include
A4,LETTER,LEGAL. - PageOrientation -
PORTRAITorLANDSCAPE. - RenderMode -
FASTfor speed,HIGH_QUALITYfor better visual fidelity.
You can modify any of these directly in the code snippet shown in the steps section.
Performance Considerations for XPS to PDF Conversion
- Render Mode - Using
PdfRenderMode.FASTreduces CPU load and speeds up conversion, which is useful for batch processing. - Stream vs File - For large documents, consider using streams instead of file paths to lower I/O overhead.
- Benchmarking - The sample measures elapsed time with
Instant. Run the conversion multiple times and calculate average duration to get a reliable benchmark. - Thread Safety - Create a separate
Converterinstance per thread; the SDK is not thread‑safe for shared instances.
Applying these tips helps you achieve consistent conversion times, especially when integrating the SDK into a servlet or a Spring Boot service.
Conclusion
XPS to PDF conversion in Java becomes straightforward with Conholdate.Total for Java. By following the steps, configuring the options, and applying performance best practices, you can generate PDF/A‑1b compliant documents efficiently. Remember to obtain a proper license for production use; you can explore pricing details on the pricing page or request a temporary license to evaluate the SDK.
Common Questions
How do I perform XPS to PDF conversion in Java using Conholdate.Total?
Use the Converter class with XpsLoadOptions and PdfConvertOptions. The sample code in this article shows the exact sequence of calls.
What Maven dependency is required for XPS to PDF conversion in Java?
Add the Conholdate Maven repository and the conholdate-total artifact as demonstrated in the setup section. The same coordinates work for Gradle.
Can I run the conversion from the command line without writing Java code?
Yes, the SDK provides a CLI tool that accepts input and output file paths along with option flags. Refer to the CLI documentation on the product page.
How can I benchmark XPS to PDF conversion performance in Java?
Wrap the conversion call with Instant.now() before and after execution, then calculate the duration. For more accurate results, run the conversion multiple times and average the timings.
