3

I am trying to convert xps to pdf using PDFsharp. I have gone through

this & this

But not able to find steps to convert XPS to PDF. Can anybody suggest me the informative link to convert xps to pdf?

I have downloaded the source of PDFSharp from here

But what should be next step? Please help me. Thanks.

P.S. I have visited all the links related to converting xps to pdf here but as I have low reputation I am not able to post more than 2 links.

UPDATE : Finally I figured it out.

I followed this.

  1. download the zips and add dll in your project.
  2. use following code

      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);
      PdfSharp.Xps.XpsConverter.Convert(pdfXpsDoc, FileName, 0);
    

    where dp should be your wpf control.

THEN

     PdfSharp.Xps.XpsConverter.Convert(sourceXpsFile, destPdfFile, 0);

DONE :)

Community
  • 1
  • 1
Learner
  • 59
  • 1
  • 7

2 Answers2

1

Based on this question and Nathan Jones work there is now a NuGet package available to do the trick.

Orace
  • 7,822
  • 30
  • 45
0

The next step: UNZIP the file you downloaded. ;-)
Unzip PDFSharp-MigraDocFoundation-1_31.zip.

Go to PDFsharp\dev\XPStoPDF and open the solution there.

In the PdfSharp.Xps.UnitTests project, go to folder XpsFiles and open SampleXpsDocuments_1_0.cs.

The tests in that file show how to convert XPS to PDF.

  • Thank you Sir for the answer. (Y) After posting question I gone through http://www.pdfsharp.net/(S(pb3zlpjvn3xe43juqv332hyo))/NuGetPackage_PDFsharp-wpf.ashx and installed package in my wpf application but still looking for the solution. – Learner Sep 22 '15 at 11:22