2

I need to convert an XPS file I create with my application to a PDF file, what is the best way to do so? I prefer this to be done from inside C# using a managed assembly.

Open source is preferred upon third party solutions

David MZ
  • 3,648
  • 6
  • 33
  • 50
  • 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

4 Answers4

4

You can use the XpsDocument class to read the XPS files, then use a PDF library (such as Report.Net or #PDF) to export it. I used #PDF back in .NET 1.1, but not sure if it can be easily converted to .NET 2.0.

#PDF: http://sharppdf.sourceforge.net/

Report.NET: http://report.sourceforge.net/

Jim
  • 1,695
  • 2
  • 23
  • 42
  • 2
    It seems to have methods to create objects in the PDF no conversion options, how did you intend to convert it – David MZ Jun 18 '11 at 16:41
  • I think you'll need to convert the XpsDocument to an intermediate format, then convert that to PDF. Also found an interesting project: NDeks Xps (http://www.ndesk.org/Xps). – Jim Jun 18 '11 at 19:06
2

An open source managed assembly might be hard to find, but you can look at tallcomponents.com for a commercial product that might help, You can have a look at GhostScript.com, its open source and supports both XPS and PDF, although you may have issues redistributing it without a license.

Mark Redman
  • 24,079
  • 20
  • 92
  • 147
1

XPS to PDF document conversion using Ghostscript. Please refer below code snippet to convert XPS to PDF

Process process = new Process();
process.StartInfo.FileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ghostxps-9.54.0-win32", "gxpswin32.exe");
process.StartInfo.Arguments = $"-sDEVICE=pdfwrite -sOutputFile=\"{pdfFilePath}\" -dNOPAUSE \"{xpsFilePath}\"";
process.Start();
process.WaitForExit();

Please refer below links for more details. click here.

Tony Stark
  • 434
  • 4
  • 13
-1

Although it is not free, Amyuni PDF Creator .Net supports loading XPS files and saving them as PDF.

Usual disclaimer applies.

yms
  • 10,361
  • 3
  • 38
  • 68