How to keep high quality image when convert XPS to PDF in C#

We have already had an article of showing how to convert the XPS files into PDF file. Starts from Spire.PDF V3.8.68, it newly supports to keep the high quality image on the resulted PDF file from the XPS document. Spire.PDF offers a property of pdf.UseHighQualityImage to set the image quality before loading the original XPS file. This article will focus on demonstrate how to save image with high quality for the conversion from XPS to PDF.

Here comes to the code snippets:

Step 1: Create a PDF instance.

PdfDocument pdf = new PdfDocument();

Step 2: Set the value of UseHighQualityImage as true to use the high quality image when convert XPS to PDF.

pdf.UseHighQualityImage = true;

Step 3: Load the XPS document by use either the method of pdf.LoadFromFile() or pdf.LoadFromXPS().

pdf.LoadFromFile("Sample.xps",FileFormat.XPS);

Step 4: Save the document to file.

pdf.SaveToFile("result.pdf");

Effective screenshot of the high quality image after saving XPS as PDF file format:

How to keep high quality image when convert XPS to PDF in C#

Full codes:

{
    PdfDocument pdf = new PdfDocument();

    pdf.UseHighQualityImage = true;

    pdf.LoadFromFile("Sample.xps",FileFormat.XPS);
    //pdf.LoadFromXPS("Sample.xps");

    pdf.SaveToFile("result.pdf", FileFormat.PDF);

}