c# - LibreOffice 在 ASP.NET MVC 中将 XLSX 转换为 PDF

标签 c# asp.net-mvc pdf libreoffice

4.3 版

在 C# 中,我尝试使用 headless 选项将 XLSX 转换为 PDF,但是当我从 ASP.NET 或简单的命令提示符运行它时没有任何反应。

            var pdfProcess = new Process();
            pdfProcess.StartInfo.FileName = exe;
            pdfProcess.StartInfo.Arguments = param + " \"" + fullDocPath +"\"";
            pdfProcess.Start();

exe 和参数在哪里:

C:\Program Files (x86)\LibreOffice 4\program\soffice.exe

  -norestore -nofirststartwizard -nologo -headless -convert-to pdf  "c:\UDS_Docs\temp\Teller Roster National.xlsx"

我使用 GUI 来测试 LibreOffice 可以转换文件并且工作正常。

最佳答案

以下是如何在 ASP.NET MVC 网站上免费将 Excel、Word 等转换为 PDF:

免费安装 LibreOffice

将当前目录设置为与现有 XLS 相同的文件夹。这似乎是缺失的部分。

运行这个:

"C:\Program Files (x86)\LibreOffice 4\program\soffice.exe"  -norestore -nofirststartwizard -headless -convert-to pdf  "TheFile.xlsx"

在 C# 中:

var pdfProcess = new Process();
pdfProcess.StartInfo.FileName = exePdf;
pdfProcess.StartInfo.Arguments = "-norestore -nofirststartwizard -headless -convert-to pdf  \"TheFile.xlsx\"";
pdfProcess.StartInfo.WorkingDirectory = docPath; //This is really important
pdfProcess.Start();

确保您的 WorkerProcess 可以访问该 exe,默认情况下它没有。

关于c# - LibreOffice 在 ASP.NET MVC 中将 XLSX 转换为 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26814534/

相关文章:

c# - 如何更改表达式树中的类型?

asp.net-mvc - 在 Razor 语法中为 Telerik MVC Grid 定义模板列

ios - 显示具有将图片放在页面顶部的功能的 pdf

java - itext 保护 pdf 不被修改

具有命名/标记类型的 C# 字典

c# - 找不到标准 Assets |统一 2018.3.0f2

c# - CTP5 EF代码第一题

jquery - MVC - 使用JQuery触发主视图中部分 View 的提交事件

pdf - 如何使用Ghostscript将XPS转换为PDF或XPS转换为DOC?

c# - 编辑自定义 SSIS PipelinComponent 抛出错误 "value of ' null' is not valid for 'stream' "