wooio / htmltopdf-java

An HTML to PDF conversion library written in Java, based on wkhtmltopdf.
MIT License
173 stars 97 forks source link

IO Stream not closing #11

Closed jcorbett55 closed 6 years ago

jcorbett55 commented 6 years ago

During public boolean convert(String path), the generated file remains locked in the IO stream and cannot be manipulated during runtime,. My inital guess is that the following is not closing up all connections when run. finally { wkHtmlToPdf.wkhtmltopdf_destroy_converter(converter); }

benbarkay commented 6 years ago

Are you on Windows? Gonna try to reproduce this later today.

benbarkay commented 6 years ago

@jcorbett55 I could not reproduce. This test passes on a Windows 10 machine:

@Test
public void itReleasesHandleToPdfFileWhenConversionIsDone() throws IOException {
    File file = tempFolder.newFile();
    HtmlToPdf.create()
            .object(HtmlToPdfObject.forHtml("<p>test</p>"))
            .convert(file.getPath());
    assertTrue(file.renameTo(file));
}

I was also able to delete the file manually while this test was in a Thread.sleep.

It would be very helpful if you could provide a snippet that I could run that reproduces the behavior.

benbarkay commented 6 years ago

Closing due to inactivity. Welcome to re-open if you have more input.

jcorbett55 commented 6 years ago

Found out another process was getting called via another library and that was locking it. So it was invalid. Thanks.

benbarkay commented 6 years ago

@jcorbett55 try playing around with HtmlToPdfObject#loadImages and HtmlToPdfObject#javascriptDelay

jcorbett55 commented 6 years ago

here's my code. I will try with the javascriptDelay. see if that works. HtmlToPdfObject htmlObject = HtmlToPdfObject.forHtml(document); htmlObject.loadImages(true); HtmlToPdf htmlToPdf = HtmlToPdf.create().object(htmlObject); Boolean success = htmlToPdf.convert(TEMP_FOLDER_LOCATION + pdfFileName);