
Convert XPS to PDF programmatically in C#
The XPS files define the visual appearance and composition besides rendering and printing rules in XML markup. Since XPS documents are popular because of their unique capability to manage annotations or signatures, people may have these files but are keen to convert them into PDFs. We’ll discuss this specific scenario below in the article and will learn how to convert XPS to PDF programmatically in C#.
The following points will be covered in this article:
C# .NET API to convert XPS to PDF
We will use Conholdate.Total for .NET to convert XPS to PDF programmatically. You can download the DLL or install this XPS conversion API using NuGet.
Install-Package Conholdate.Total
How to convert XPS to PDF using C#
You can convert XPS files to PDFs by following the steps below:
- Initialize the objects of Stream class for both XPS and PDF documents.
- Create an instance of XpsDocument class by using the XPS stream (created in the previous step) and the object of XpsLoadOptions class as parameters.
- Initialize object of PdfSaveOptions class by specifying TextCompression, ImageCompression, JpegQualityLevel and other options.
- Create an object of PdfDevice class from the output stream as created in the 1st step.
- Save the PDF document by using XpsDocument.Save(Device device, SaveOptions options) and pass it PdfDevice and PdfSaveOptions objects as created in earlier steps.
The following code shows how to convert XPS to PDF using C#.
Get a free license
You can acquire a free temporary license to test the API without evaluation limitations.
Conclusion
In this article, we have covered the procedure of XPS to PDF conversion. Finally, we hope you have learned how to convert XPS to PDF in C# using an XPS conversion API. You may visit the documentation to explore other features of the XPS conversion library.
Ask a question
You can let us know your questions or queries on our forum.