Reputation: 69
I am trying to convert xps to pdf using PDFsharp. I have gone through
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.
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 :)
Upvotes: 3
Views: 10162
Reputation: 8359
Based on this question and Nathan Jones work there is now a NuGet package available to do the trick.
Upvotes: 1
Reputation: 21689
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.
Upvotes: 0