Forum How do I...?

Java wrapper outputstream empty..

TomDoes
Hi,

I'm using the java wrapper to create a PDF

prince.convert("/filepath/file.html); works and generates a pdf in the same folder, however when I use an OutputStream it stays empty.

This is my implementation

OutputStream os_file = new FileOutputStream("test.pdf");

Prince prince = new Prince("/usr/local/bin/prince");
prince.setVerbose(true);
prince.setDebug(true);


prince.convert("/filepath/file.html", os_file);

Any idea what i'm doing wrong?
mikeday
Can you use setLog() to capture error/warning messages? Make sure the log directory is writable.
TomDoes
When I remove the trailing '-' from the command my log is written, with no errors and the pdf is created in the same folder as the html (not to the output stream for some reason) but when I leave the trailing '-' in the public boolean convert(String xmlPath, OutputStream pdfOutput) method, nothing happens..

  1. prince.txt21.5 kB
TomDoes
This is the output when i use a BufferedReader to print the stream to the console of my java app.

prince: error: no output filename specified
prince: error: Try 'prince --help' for more information.

This is coming from the public boolean convert(String xmlPath, OutputStream pdfOutput) method

It seems that the '-' for writing to the standard output is not working

Edited by TomDoes

TomDoes
I fixed it, there is a bug in the wrapper. When i add
cmdline.add("-o");
in the public boolean convert(String xmlPath, OutputStream pdfOutput) method just before the cmdline.add("-"); It works..


mikeday
Which version of Prince are you using? I'm wondering when this was broken.
TomDoes
I'm using prince-9.0r5-macosx.tar.gz with source files of the java wrapper r8
mikeday
Sorry for the inconvenience, we forgot to update this method when we changed the command-line syntax. I have updated the wrapper to add -o, the new version is r9.

The old syntax still works if you read the input from a stream as well, eg. this command-line is valid:
prince -

But reading from a file and writing to a stream requires an explicit -o argument:
prince file.html -o -

TomDoes
No problem, thanks for the quick support!