我正在开发一个用 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 文件,我是否应该将其转换为字节数组并将其设置在某个地方?
先感谢您。