wpf 使用 PDFsharp 或 iTextsharp 将 XPS 转换为 PDF
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32714386/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Convert XPS to PDF using PDFsharp or iTextsharp
提问by Learner
I am trying to convert xps to pdf using PDFsharp. I have gone through
我正在尝试使用 PDFsharp 将 xps 转换为 pdf。我经历过
But not able to find steps to convert XPS to PDF. Can anybody suggest me the informative link to convert xps to pdf?
但无法找到将 XPS 转换为 PDF 的步骤。有人可以建议我将 xps 转换为 pdf 的信息链接吗?
I have downloaded the source of PDFSharp from here
我已经从这里下载了 PDFSharp 的源代码
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.
PS 我在这里访问了所有与将 xps 转换为 pdf 相关的链接,但由于我的声誉很低,我无法发布超过 2 个链接。
UPDATE : Finally I figured it out.
更新:最后我想通了。
I followed this.
我跟着这个。
- download the zips and add dll in your project.
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.
- 下载 zips 并在您的项目中添加 dll。
使用以下代码
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);其中 dp 应该是您的 wpf 控件。
THEN
然后
PdfSharp.Xps.XpsConverter.Convert(sourceXpsFile, destPdfFile, 0);
DONE :)
完毕 :)
回答by I liked the old Stack Overflow
The next step: UNZIP the file you downloaded. ;-)
Unzip PDFSharp-MigraDocFoundation-1_31.zip.
下一步:解压缩您下载的文件。;-)
解压 PDFSharp-MigraDocFoundation-1_31.zip。
Go to PDFsharp\dev\XPStoPDF and open the solution there.
转到 PDFsharp\dev\XPStoPDF 并在那里打开解决方案。
In the PdfSharp.Xps.UnitTests project, go to folder XpsFiles and open SampleXpsDocuments_1_0.cs.
在 PdfSharp.Xps.UnitTests 项目中,转到文件夹 XpsFiles 并打开 SampleXpsDocuments_1_0.cs。
The tests in that file show how to convert XPS to PDF.
该文件中的测试显示了如何将 XPS 转换为 PDF。

