Search code examples
javapdfapache-fop

Apache FOP Return Code 1 on PDF Generation


I am attempting to use the latest version of Apache FOP to generate PDF's. When doing this however, I am getting an error with the return code. For some reason it is now returning "1" instead of "0" on the process execute.

ProcessBuilder processBuilder = new ProcessBuilder(commandWords);
processBuilder.directory(fopFolder);
processBuilder.redirectErrorStream(true);
StringBuilder outputBuilder = new StringBuilder();
Process process = processBuilder.start();
exitCode = process.waitFor(); //Should return 0, actually returns 1

The command words I am passing are...

path -jar fop.jar -c configPath -fo {null} -pdf outputPath

Or depending on situation...

path -Xms256m -Xmx{maxmemory} -jar fop.jar -c configFile -fo {null} -pdf outputPath

I also managed to get this error out of it later which I suspect may be the cause. I will add an answer later as required if I find my own solution.

Error occurred during initialization of VM Initial heap size set to a larger value than the maximum heap size

Any advice on this subject is appreciated, if you require additional information I would also be happy to update my question, as I am not 100% sure what information is required to debug this problem.

  • Java Version: 8
  • Apache FOP: 2.1

Solution

  • After looking into this further, we are running a tomcat server, which was in turn launching the Apache FOP. It was running out of memory because the parameters it was attempting to parse were incorrect.

    We redid the setup and instead passed the following two changes to the FOP as default and it worked perfectly. We believe the default was something either invalid or too low to handle the process.

    path -Xms256m -Xmx1024m -jar fop.jar -c configFile -fo {null} -pdf outputPath