簡體   English   中英

在.Net Core中將.docx / .doc文件轉換為.pdf

[英]Converting .docx/.doc files to .pdf in .Net Core

我正在嘗試將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的最佳方法是什么?

此Node.js程序包無法運行的原因與.NET Core不相同的原因相同:它調用的是Microsoft.Office.Interop ,並且僅在安裝了Office interop內容的Windows計算機上運行。

基本上,.NET Core編譯時​​會知道Microsoft.Office.Interop在安裝時可能不可用,因此會引發錯誤。 但是,JS沒有進行編譯,並且在運行時發現它已安裝在不存在C:\\Windows\\assembly\\GAC_MSIL\\...的服務器/容器中。

在.NET Core中包裝Node.js應用程序只會將這個問題從編譯時轉移到運行時。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM