Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I was trying to convert a DOCX file to PDF file, found this vb script code which perfectly converts DOCX to PDF file, it uses .bat file for file generation. The code can be executed through java.

I am facing a strange problem, when I execute the code on my local machine, the file is generated, but when I deployed the app on Server , the code executes but the file is not generated.

Do we need any permission to execute commands through java on server side?

Following is the details:

Local Operating system : > Windows 10.
Application server : > Apache Tomcat 7.0.75


Server Operating system : >Windows Server 2012 R2 Standard
Application server : >Apache Tomcat 7.0.75

What I have tried:

Code: 1)Java
public static void generatePDF() {
    try {

        File file = new File("C:\\Docx_To_Pdf_Converter\\errorLog.txt");
        PrintStream printStreamToFile = new PrintStream(file);
        System.setOut(printStreamToFile);


        String docToPdf = "C:\\Docx_To_Pdf_Converter\\doc2pdf.bat";

        File docPath = new File("C:\\Docx_To_Pdf_Converter\\Letter1.docx");

        File pdfPath = new File("C:\\Docx_To_Pdf_Converter\\LetterPDF.pdf");

        String command = String.format("%s %s %s", docToPdf, docPath, pdfPath);

        Process process = Runtime.getRuntime().exec(command);

        // The next line is optional and will force the current Java 
        //thread to block until the script has finished its execution.

        process.waitFor();
    } catch (IOException e) {      
        e.printStackTrace();
    } catch (InterruptedException e) {            
        e.printStackTrace();
    }

}


2)and the .bat file code:

@Echo off
pushd %~dp0
cscript C:\Docx_To_Pdf_Converter\doc2pdf.vbs %1 %2
Posted
Comments
Richard MacCutchan 27-Nov-17 3:53am    
Run the bat file's commands in a command window on the server and see what happens. Chances are that the paths in your Java code do not relate to the correct locations on the server.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900