I use the following Java Code to print a PDF Document:
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintService(printer);
File file = new File(fileName);
PDDocument doc = PDDocument.load(file);
PDFPageable pageable = new PDFPageable(doc);
job.setPageable(pageable);
System.out.println("-- before printing --");
job.print();
System.out.println("-- after printing --");
doc.close();
the output on console is:
-- before printing --
Aug 03, 2018 12:05:09 PM org.apache.pdfbox.cos.COSDocument finalize
WARNUNG: Warning: You did not close a PDF Document
-- after printing --
Why do I get this warning?
As discussed in the comments - the problem went away by updating to the latest jdk version, here: from JDK 1.8.0_131 to 1.8.0_181. I can only suspect that the older jdk had a bug that objects were prematurely marked as "unused" and thus were finalized.