Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert XPS to PDF using PDFsharp or iTextsharp

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 :)

like image 565
Learner Avatar asked Sep 16 '26 00:09

Learner


1 Answers

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

like image 164
Orace Avatar answered Sep 19 '26 05:09

Orace



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!