将 FlowDocument 转换为 PDF 的最佳方法是什么
您会如何建议我将 FlowDocument 转换为 PDF 以附加到电子邮件中?
FlowDocument 是动态的,而不是静态的。
我希望能够将 PDF 作为 byte[] 存储在内存中,而不是存储在磁盘上,但这是可以协商的。
感谢您的帮助!
How would ya'll recommend that I convert a FlowDocument to PDF to be attached to an EMail?
The FlowDocument is dynamic, not static.
I would prefer to be able to store the PDF in memory as a byte[], rather than on disk, but that is negotiable.
Thanks for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
免责声明:我是 XamlToPDF 库的作者,但它对任何类型的使用都是免费的。
http://xamltopdf.codeplex.com/
创建 PDF 非常容易,它还支持表格和图像。
Disclaimer: I am writer of XamlToPDF Library, however it is free for any type of use.
http://xamltopdf.codeplex.com/
Its very easy to create PDF, it supports Tables and images as well.
我假设您希望以编程方式而不是手动过程进行此操作。
方法 1: 安装 PDF 驱动程序,例如 Amyuni 或 < a href="http://www.primopdf.com/" rel="nofollow">PrimoPDF。使用所需的 PrintTicket/页面大小将 FlowDocument 打印到打印驱动程序。您从中获得的 PDF 应该是一个相当不错的转换。其中一些驱动程序(例如 Amyuni)具有 SDK,您可以通过编程方式控制此过程。
方法 2: 使用 XPS 驱动程序以编程方式打印到 XPS,无需“另存为”对话框; Windows DDK 中有一个示例,您可以相当轻松地自行构建。然后使用 XPS 到 PDF 转换器,例如 NiXPS 或 Adobe SDK(太贵了,我不会发布链接) 或 GhostXPS 将 XPS 直接转换为 PDF。
方法3:使用这个,然后使用 XPS 到 PDF 转换器,例如上面提到的那些。
免责声明:我不为任何这些公司或其竞争对手工作。我使用了 Adobe SDK、Amyuni 打印机和各种 XPS 技巧,并取得了相当好的成功。没有任何方法能够以 100% 的准确率进行转换。
I am assuming you want this to occur programmatically rather than as a manual process.
Method 1: Install a PDF driver such as Amyuni or PrimoPDF. Print your FlowDocument with the desired PrintTicket / page size, to the print driver. The PDF you get from it should be a fairly good conversion. Some of these drivers (such as Amyuni) have SDKs that you can control this process programmatically.
Method 2: Print to XPS programmatically using an XPS driver without a Save As dialog; there's a sample for this in the Windows DDK you can build yourself fairly easily. Then use an XPS to PDF converter such as NiXPS or the Adobe SDK (so expensive I won't post a link) or GhostXPS to convert the XPS directly to PDF.
Method 3: Convert the flow document directly into XPS using methods like This one and then use an XPS to PDF converter such as the ones mentioned above.
Disclaimer: I don't work for any of these companies or their competitors. I've used the Adobe SDK, the Amyuni printer, and various XPS tricks with fairly good success. No method will convert with 100% accuracy.
当我需要执行此操作时,我将 FlowDocument 保存为 XPS 文件,最后使用 PDFSharp 转换为 PDF 并删除了 XPS 文件
希望这对某人有帮助
When I needed to do this I saved the FlowDocument as an XPS file and finally converted to PDF with PDFSharp and deleted the XPS file
Hope this helps someone
据我所知,你有两个选择。
第一种是使用名为 NiPDF 的专有库,或者您也可以使用 Word Interop。
您可以找到更多信息 此处
You have two options that I know of.
The first is to use a proprietary library called NiPDF, alternatively you can use Word Interop.
You can find further info here
我设法使用 PDFCreator 打印机驱动程序使其正常工作。您需要安装驱动程序才能正常工作,因此对于某些人来说这可能不是理想的解决方案。有一个可用的 COM 接口。代码或多或少看起来像这样:
I managed to get this working with the PDFCreator printer driver. You need to install the driver for this to work, so it may not be an ideal solution for some people. There is a COM interface available. The code more or less looks something like this:
您可能需要考虑 Seberix (http://www.siberix.com/) 的名为“Report Writer for .NET”的产品。它的 API 类似于 FlowDocument 中的代码,我认为当你说“动态,而不是静态”时,你想要的就是你想要的。 (但我确信也存在差异。细节决定成败)。
创建 Siberix.Report.Report 对象后,
现在可以将字节保存到数据库表或其他内容中。
You might want to consider the product called "Report Writer for .NET" by Seberix (http://www.siberix.com/). Its API is similar to the code behind in FlowDocument which I think is you want want when you said "dynamic, not static". (But I'm sure there are differences as well. Devils are in the details).
Once a Siberix.Report.Report object has been created,
Now bytes can be saved to a database table or whatever.
另一个值得关注的选项是 FlowDocumentConverter。此功能可在 NuGet 包 中找到,但要按照 文档确实有 10 页的限制。
Another option to look at is FlowDocumentConverter. This is available in a NuGet package, but per documentation does have a 10 page limitation.
就我而言,我需要基于 WPF FlowDocument 创建 PDF。我从 NuGet PdfSharp.XPS.dotNet.Core 中提取。我最终根据 Brian 的回答创建了以下函数:
我这样使用它:
In my case, I needed to create a PDF based on a WPF FlowDocument. I pulled from NuGet PdfSharp.XPS.dotNet.Core. I ended up creating the following function based on Brian's answer here.:
And I am using it like this: