"scratch file already closed" message
The "scratch file already closed" message when building is related to the premature closing of the document in Utils.pageConvertToImage(). Please remove "document.close();".
However even that isn't really enough. The PDDocument is closed, and with it resources from the PDPage object may also be closed. Some of these may be resources from other pages.
The best solution would be to include the PDDocument object in the page class. Then pass that to pageConvertToImage, and pass the page number instead of the PDPage object. If you don't know the page number, it it with doc.getPages().indexOf(page).
In Utils:
public static BufferedImage pageConvertToImage(PDDocument doc, PDPage page, int dpi, ImageType imageType) throws IOException {
PDFRenderer renderer = new PDFRenderer(doc);
return renderer.renderImageWithDPI(doc.getPages().indexOf(page), dpi, imageType);
}
Everywhere this is used, pass the document. Either it is known, or call page.getPDDoc(). For that, change the Page class so that the PDDocument is passed in construction and stored. I did that locally and my build now passes.
(Git is a pain and I hate it and this is my only weakness and it drains my energy. Here's the page class. The rest is really straight forward, but I'm willing to help over the phone or whatever else) Page.zip