【问题标题】:Converting .docx/.doc files to .pdf in .Net Core在 .Net Core 中将 .docx/.doc 文件转换为 .pdf
【发布时间】:2018-01-05 20:50:31
【问题描述】:

我正在尝试将 MS Word 文件 (.docx/.doc) 转换为 *.pdf 文件,但没有找到任何 .net 核心包可以这样做。

然后我想使用 Node.js 包,并在我的 .Net Core 应用程序中运行它。我试过node-msoffice-pdf 节点包。我首先创建了一个示例 Node 应用程序,只是为了测试这个包是否有效,但是当我运行它时,我收到以下错误:

D:\Projects\test\node_modules\edge\lib\edge.js:169
    return edge.initializeClrFunc(options);
                ^
Error: Unable to compile C# code.
----> Errors when compiling as a CLR library:
error CS0006: Metadata file 'C:\Windows\assembly\GAC_MSIL\Microsoft.Office.Interop.Word\15.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Word.dll
' could not be found
error CS0006: Metadata file 'C:\Windows\assembly\GAC_MSIL\Microsoft.Office.Interop.Excel\15.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Excel.d
ll' could not be found
error CS0006: Metadata file 'C:\Windows\assembly\GAC_MSIL\Microsoft.Office.Interop.PowerPoint\15.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Po
werPoint.dll' could not be found
error CS0006: Metadata file 'C:\Windows\assembly\GAC_MSIL\Office\15.0.0.0__71e9bce111e9429c\Office.dll' could not be found
error CS0006: Metadata file 'C:\Windows\assembly\GAC_MSIL\Microsoft.Vbe.Interop\15.0.0.0__71e9bce111e9429c\Microsoft.Vbe.Interop.dll' could not be f
ound
----> Errors when compiling as a CLR async lambda expression:
error CS0006: Metadata file 'C:\Windows\assembly\GAC_MSIL\Microsoft.Office.Interop.Word\15.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Word.dll
' could not be found
error CS0006: Metadata file 'C:\Windows\assembly\GAC_MSIL\Microsoft.Office.Interop.Excel\15.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Excel.d
ll' could not be found
error CS0006: Metadata file 'C:\Windows\assembly\GAC_MSIL\Microsoft.Office.Interop.PowerPoint\15.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Po
werPoint.dll' could not be found
error CS0006: Metadata file 'C:\Windows\assembly\GAC_MSIL\Office\15.0.0.0__71e9bce111e9429c\Office.dll' could not be found
error CS0006: Metadata file 'C:\Windows\assembly\GAC_MSIL\Microsoft.Vbe.Interop\15.0.0.0__71e9bce111e9429c\Microsoft.Vbe.Interop.dll' could not be f
ound
    at Error (native)
    at Object.exports.func (D:\Projects\test\node_modules\edge\lib\edge.js:169:17)
    at Object.<anonymous> (D:\Projects\test\node_modules\node-msoffice-pdf\lib.js:4:23)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (D:\Projects\test\server\api\todo\controller\todo-controller.js:3:14)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (D:\Projects\test\server\api\todo\route\todo-route.js:3:25)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)

在 .Net Core 中将 MS Word 文件转换为 PDF 的最佳方法是什么?

【问题讨论】:

  • 如果您不打算自己学习文件格式,我假设您知道您的首要任务是使用 Google 查找现有库。

标签: node.js pdf asp.net-core ms-word .net-core


【解决方案1】:

这个 Node.js 包不工作的原因与 .NET Core 不工作的原因相同:它调用 Microsoft.Office.Interop,并且只在安装了 Office 互操作的 Windows 机器上工作。

基本上,当 .NET Core 编译时,它知道 Microsoft.Office.Interop 在安装时可能不可用,因此会引发错误。然而 JS 没有被编译,并且在运行时发现它安装在一个服务器/容器上,而 C:\Windows\assembly\GAC_MSIL\... 不存在。

在 .NET Core 中封装 Node.js 应用程序只是将这个问题从编译时转移到运行时。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-16
    • 1970-01-01
    • 1970-01-01
    • 2020-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多