将Docx转换为Pdf在服务器计算机中不起作用

时间:2015-11-13 07:14:34

标签: java batch-file pdf cmd

在我的项目中,我必须将docx转换为pdf。要将docx转换为pdf,我使用processbuilder对象运行bat文件。它在我的本地环境中工作,但不在服务器机器上工作,同时它不会抛出任何异常。以下是我的代码。

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try{

        String path = "C:\\selva\\";
        String arg1 = "C:\\kumar\\a.docm";
        String command = "cmd.exe /c start " + path + "runner.bat "+arg1;



        String runCommand=path + "runner.bat";


        ProcessBuilder pb = null;

        pb = new ProcessBuilder(runCommand, arg1);
        pb.redirectErrorStream(true);
        pb.start();


         response.sendRedirect("/GENERATEPDFFROMDOCX/genPDF.jsp");  
        }catch(Exception ex){
            ex.printStackTrace();
        }
    }

Runner.bat

echo %1
"C:\Program Files\Microsoft Office 15\root\office15\winword.exe" /mExportToPDFext %1>ONE.TXT

Local Machine Log:
C:\Users\Selva\Desktop\eclipse>echo C:\kumar\a.docm 
C:\kumar\a.docm

C:\Users\Selva\Desktop\eclipse>"C:\Program Files\Microsoft Office 15\root\office15\winword.exe" /mExportToPDFext C:\kumar\a.docm 1>ONE.TXT 

Error Code is 0
Process Finished
Server Log:
C:\Program Files\Apache Software Foundation\Tomcat 8.0>echo C:\kumar\a.docm 
C:\kumar\CarLoanAgreement.docm

C:\Program Files\Apache Software Foundation\Tomcat 8.0>"C:\Program Files\Microsoft Office 15\root\office15\winword.exe" /mExportToPDFext C:\kumar\a.docm 1>ONE.TXT 
The process cannot access the file because it is being used by another process.

Error Code is 1
Process Finished

上述代码有什么问题?

1 个答案:

答案 0 :(得分:0)

在您的代码中,您正在硬编码某些软件的路径。

为什么它不在服务器上工作的最可能的原因是:

  • 服务器使用不同类型的操作系统
  • 路径不存在于 服务器
  • 未安装转换文档的软件
  • 的 在服务器上运行Web应用程序的用户没有权限 执行任何事情