openhtmltopdf
openhtmltopdf copied to clipboard
PdfRendererBuilder's run method closes the OutputStream passed using the toStream method
The documentation of the PdfRendererBuilder
's toStream
method states that when calling the run
method, the passed OutputStream
will not be closed.
That's not true in practice : the createPdf
/ createPdfFast
methods of the PdfBoxRenderer
class both call _pdfDoc.save(os);
, which itself closes the OutputStream.
My workaround is to wrap my outputstream in a FilterOutputStream on which I override the close method :
OutputStream pdfOutput = ... //my original outputstream
OutputStream nonCloseablePdfOutput = new FilterOutputStream(pdfOutput) {
@Override
public void close() throws IOException {
//openhtmltopdf has a bug where it closes the stream at the end of the "run" method
//even though the documentation states otherwise.
}
};
builder.toStream(nonCloseablePdfOutput);