News Category

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

2016-11-24 08:27:52 Written by  support iceblue
Rate this item
(0 votes)

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:

using Spire.Pdf;

namespace ConvertXPStoPDF
{
    class Program
    {
        static void Main(string[] args)
        {
            PdfDocument pdf = new PdfDocument();
           
            pdf.UseHighQualityImage = true;

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

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

Additional Info

  • tutorial_title: Keep high quality image when convert XPS to PDF
Last modified on Sunday, 26 September 2021 01:30