Converting XPS document to PDF
5 Dec 20241 minute to read
The XPS (XML Paper Specification) document format is a fixed document format which consists of structured XML markup that defines the layout of a document and the visual appearance of each page, along with rendering rules for distributing, archiving, rendering, processing and printing the documents.
The following code example illustrates how to converting XPS document to PDF using XPSToPdfConverter class.
//Initialize XPS to PDF converter.
XPSToPdfConverter converter = new XPSToPdfConverter();
//Open the XPS file as stream.
FileStream fileStream = new FileStream("Input.xps", FileMode.Open, FileAccess.ReadWrite);
//Convert the XPS to PDF.
PdfDocument document = converter.Convert(fileStream);
//Creating the stream object.
MemoryStream stream = new MemoryStream();
//Save the document into stream.
document.Save(stream);
//Close the documents.
document.Close(true);
//Create converter class.
XPSToPdfConverter converter = new XPSToPdfConverter();
//Convert the XPS to PDF document.
PdfDocument document = converter.Convert(xpsFileName);
//Save and close the document.
document.Save("Sample.pdf");
document.Close(true);
'Create converter class
Dim converter As New XPSToPdfConverter()
'Convert the XPS to PDF
Dim document As PdfDocument = converter.Convert(xpsFileName)
'Save and close the document
document.Save("Sample.pdf")
document.Close(True)
You can download a complete working sample from GitHub.
NOTE
The Syncfusion® .NET PDF library supports converting XPS to PDF with Syncfusion.XpsToPdfConverter.Net.Core NuGet package reference in ASP.NET Core application.