Ian*_*ink 4 c# pdf asp.net-mvc libreoffice
版本4.3
在C#中,我试图使用无头选项将XLSX转换为PDF,但是当我从ASP.NET或简单的命令提示符运行时没有任何反应.
var pdfProcess = new Process();
pdfProcess.StartInfo.FileName = exe;
pdfProcess.StartInfo.Arguments = param + " \"" + fullDocPath +"\"";
pdfProcess.Start();
Run Code Online (Sandbox Code Playgroud)
exe和params是:
C:\Program Files (x86)\LibreOffice 4\program\soffice.exe
-norestore -nofirststartwizard -nologo -headless -convert-to pdf "c:\UDS_Docs\temp\Teller Roster National.xlsx"
Run Code Online (Sandbox Code Playgroud)
我使用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"
Run Code Online (Sandbox Code Playgroud)
在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();
Run Code Online (Sandbox Code Playgroud)
确保您的WorkerProcess可以访问exe,默认情况下不会.
| 归档时间: |
|
| 查看次数: |
4273 次 |
| 最近记录: |