I use wkhtmltopdf in my java project with ProccessBuilder and Process:
ProcessBuilder pb = new ProcessBuilder("wkhtmltopdf.exe", "input.html", "output.pdf");
Process process = pb.start();
This solution uses a html file as input and save output as pdf file on disk. But my html isn't a file, it's an OutputStream and I want to create pdf file on fly and don't want save it on disk.
is there a way for passing parameter with OutputStream and getting result as another OutputStream?
If you pass "-" instead of "output.pdf" you should get the output as stream. Then you might be able to grab that stream, but make sure to test beforehand and bind into stderr and stdout as well and debug both their output as wkhtmltopdf can be a bit stubborn :)
In C# the forwarding is fairly easy and stdin/stderr/stdout are streams. You have to test with all three as wkhtml outputs to both, one for the pdf output and one for user interface output that you see when launching from command line. Sorry for the lack of Java or a working example, I haven't actually tried this as my processes are queued and they write to disk.
Process _process = new Process();
// Other stuff here
_process.StartInfo.RedirectStandardError = true;
StreamReader sr = _process.StandardError;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With