【发布时间】:2020-02-22 01:48:56
【问题描述】:
我正在开发一个用 c# 编写的 UWP 应用程序,我需要转换为 pdf: - 办公文件(doc、docx、xls、xlsx、ppt、pptx) - 图片 - 网页
应用程序必须在 x86、x64、ARM、ARM64 架构中工作。
我知道市场上有第三方转换器库,但只有少数可以在 ARM64 环境或 UWP 中工作。
我的想法是使用(在 Windows 10 中)允许用户将大多数文件格式保存为 PDF 的“Microsoft PDF 打印机”。
我发现很多帖子都在问同样的问题,但没有一个真正包含有用的答案。
我找到并测试的代码如下:
PrintDocument doc = new PrintDocument()
{
//DocumentName = safeDir + fileName,
PrinterSettings = new PrinterSettings()
{
// set the printer to 'Microsoft Print to PDF'
PrinterName = "Microsoft Print to PDF",
// tell the object this document will print to file
PrintToFile = true,
// set the filename to whatever you like (full path)
PrintFileName = safeDir + fileName,
}
};
doc.Print();
以上代码生成一个有效但为空的 pdf。 应该如何设置原始文件内容?
例如,如果我有一个名为 myreport.docx 的 Word 文件,我应该将其转换为字节数组并将其设置在某处吗?
提前谢谢你。
【问题讨论】:
-
使用即将推出的 WinUI,您将能够在 Win32 应用模型上运行 UWP 上使用的 UI。这将使进行各种 PDF 操作变得更加容易。查看#MSIgnite,保存日期:query.prod.cms.rt.microsoft.com/cms/api/am/binary/RE3TlM8
标签: c# pdf uwp converters virtual-printer