6

I did a lot of digging to figure out an easy way to convert an XPS document into a PDF. There are many tools that can do this but they are not free. Is there a free alternative?

Orace
  • 7,822
  • 30
  • 45
Bolo
  • 1,494
  • 1
  • 19
  • 19
  • 1
    I found a way to do this natively in Windows using the Microsoft PDF Printer. Check it out: https://stackoverflow.com/a/58566537/1469494 – Shahin Dohan Oct 25 '19 at 22:41

1 Answers1

9

A quick google search led me to this: http://www.nathanpjones.com/wp/2013/03/output-to-pdf-in-wpf-for-free/

I was able to get it to work after I trimmed down some of the code I did not need. Here is the result:

using (PdfSharp.Xps.XpsModel.XpsDocument pdfXpsDoc = PdfSharp.Xps.XpsModel.XpsDocument.Open(xpsPath))
{
    PdfSharp.Xps.XpsConverter.Convert(pdfXpsDoc, pdfPath, 0);
}

The 2 path variables are just strings.

You need to reference these 2 dll's: http://www.nathanpjones.com/wp/wp-content/uploads/2013/03/PdfSharpXpsBin.zip

Many thanks to Nathan for sharing this information!

Edit: Nathan work is available as a NuGet package here.

Orace
  • 7,822
  • 30
  • 45
Bolo
  • 1,494
  • 1
  • 19
  • 19
  • Note: If you need to convert documents that have more than 50 pages you will need to edit the PDFSharp source code – Bolo Mar 17 '15 at 19:54
  • Not sure why people are down voting without an explanation or alternative solution, especially since this is a working solution. Am I missing something? – Bolo Mar 17 '15 at 21:14
  • 1
    I did not downvote. You asked a question - and provided the answer minutes later. And the tag for the answer (PDFsharp) is already set for the question. That looks odd to me. Some folks downvote questions that show little or no effort and even downvote answers given to such questions. What are the intentions behind your question and your answer? – I liked the old Stack Overflow Mar 18 '15 at 10:08
  • 1
    When I created the question I marked it as a question/answer where you answer your own question. I thought the point of those was to help share knowledge? When i did a google search i did not find anything on this site so I thought there might be value to add this information here. Now that I looked more thoroughly I did find where on this site the issue was fixed: http://stackoverflow.com/questions/13848223/wpf-to-xps-to-pdf I guess I could remove it but I I still maintain that this Q/A will be much easier to use than sifting thru all the posts in that other thread. – Bolo Mar 19 '15 at 15:48
  • I have used this site for years but have never really contributed anything so I guess I need to "catch up" with everyone else on how things work. Thanks @PDFsharp-team for your feedback and great product!. – Bolo Mar 19 '15 at 15:50
  • 1
    It's OK for SO to answer your own question immediately and it's OK for me. But questions asking to find a tool are considered off-topic - maybe that's the problem here. – I liked the old Stack Overflow Mar 19 '15 at 17:03
  • BCLs could be considered tools: Encryption, Compression, and more. This question/answer is not a debugging tool, or a standalone converter application, it's a software library and particular configuration which solves a problem. – Kind Contributor Feb 27 '16 at 01:50
  • 1
    idk why these ppl are against this post, but this is awesome, saved me today boss!!!!!!!! don't listen to them – Grijan Feb 06 '19 at 11:30