tabula-java icon indicating copy to clipboard operation
tabula-java copied to clipboard

Hangs when launched from within Java app, but not from command line

Open fynesr opened this issue 6 years ago • 0 comments

I'm launching the executable JAR from within a Java app that I've written (Java 1.8.0_190). The command is:

java -jar /home/rfynes/tabula/tabula-1.0.3-jar-with-dependencies.jar --stream --format JSON --pages all /home/rfynes/tabula/input/CK105754F.pdf

For the majority of the PDF files that I process, there are no problems, but for a small bunch of PDFs the command hangs indefinitely. I can see the command is still running. Occasionally, the process will consume a very small amount of memory and CPU, but I have no idea what it's doing.

However, if I run that exact same Tabula command myself on the command line, then it completes and returns the expected output in a few seconds.

One of the files that I'm having trouble with has 11 pages (that file is attached), and if I tell it to process a range of pages instead e.g. 1-10 it completes successfully from within the Java app. It also works if I tell it to only process page 11. Specifying the range 1-11 will hang though. Here's some code I'm using for testing:

` public static void main(String[] args) throws Exception { if (args.length != 1) { throw new Exception("Expected: folio ID as argument"); } String folioID = args[0];

String[] command = new String[] {
        "java", "-jar", Config.tabulaJARFile,
        "--stream",
        "--format", "JSON",
        "--pages", "all",
        String.format("%s/%s.pdf", Config.TABULA_INPUT_DIR, folioID)
};

System.out.println("Executing ==> " + String.join(" ", command));
Process process = Runtime.getRuntime().exec(command);

System.out.println("Waiting...");
int exitCode = process.waitFor();

if (exitCode != 0) {
    throw new Exception("Invalid exit code ["+exitCode+"]");
}
System.out.println("Retrieving input stream...");
InputStream output = process.getInputStream();

String jsonData = IOUtils.toString(output, "UTF-8");
System.out.println(jsonData);

} ` CK105754F.pdf

fynesr avatar Jun 10 '19 14:06 fynesr