0

I am working on a code which will help conversion of XPS to PDF. Does the NuGet library have a free library which can help me achieve the above or if I can write my own C# code for the conversion. Not sure where to start with.

I have been searching for free libraries, came across iTextSharp not sure if it supports XPS to PDF conversion because I don't see a word about XPS in the NuGet gallery description https://www.nuget.org/packages/iTextSharp/5.5.13.1

  • There's a native Windows way to convert XPS or FixedDocument to PDF using the Microsoft PDF Printer: https://stackoverflow.com/q/58517394/1469494 – Shahin Dohan Oct 26 '19 at 20:26
  • Does this answer your question? [Is ther any open tool to convert XPS to PDF?](https://stackoverflow.com/questions/29108319/is-ther-any-open-tool-to-convert-xps-to-pdf) – Orace Jun 12 '20 at 08:06
  • Please refer below link to XPS to PDF Conversion free http://www.codesanitize.com/2021/04/c-xps-document-creation-using-microsoft.html – Tony Stark Apr 18 '21 at 07:10

1 Answers1

3

PDFsharp seems to be what you want. See WPF to XPS to PDF.

Also see https://nathanpjones.com/2013/03/output-to-pdf-in-wpf-for-free/:

using System.IO;
using System.IO.Packaging;
using System.Windows.Xps.Packaging;
using System.Windows.Xps;
MemoryStream lMemoryStream = new MemoryStream();
Package package = Package.Open(lMemoryStream, FileMode.Create);
XpsDocument doc = new XpsDocument(package);
XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(doc);
writer.Write(dp);
doc.Close();
package.Close();
var pdfXpsDoc = PdfSharp.Xps.XpsModel.XpsDocument.Open(lMemoryStream);

Then

PdfSharp.Xps.XpsConverter.Convert(pdfXpsDoc, d.FileName, 0);

Or for an XPS file,

PdfSharp.Xps.XpsConverter.Convert(sourceXpsFile, destPdfFile, 0);
Bondolin
  • 2,793
  • 7
  • 34
  • 62
  • where were you able to get the System.Windows.Xps DLL from? My NPM does not have it on VS '19 – tCoe Aug 27 '20 at 14:29