[ https://issues.apache.org/jira/browse/PDFBOX-3612?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15714494#comment-15714494 ]
André Heuner commented on PDFBOX-3612: -------------------------------------- First of all thanks for your quick reply. May be I missed an important log line to mention: [2016-12-02-08:24:46] WARN [org.apache.pdfbox.cos.COSDocument] Warning: You did not close a PDF Document To me the messages above seemed to be related to this warning. May be I'm wrong. Strange thing is: this message is shown if I omit the overlay.close() command. If overlay.close() is called I get the follwing error: {code} [2016-12-02-09:38:38] ERROR [com.remondis.rums.ip.service.activities.InvoiceSender] Error saving file: COSStream has been closed and cannot be read. Perhaps its enclosing PDDocument has been closed? java.io.IOException: COSStream has been closed and cannot be read. Perhaps its enclosing PDDocument has been closed? at org.apache.pdfbox.cos.COSStream.checkClosed(COSStream.java:77) at org.apache.pdfbox.cos.COSStream.createRawInputStream(COSStream.java:125) at org.apache.pdfbox.pdfwriter.COSWriter.visitFromStream(COSWriter.java:1192) at org.apache.pdfbox.cos.COSStream.accept(COSStream.java:383) at org.apache.pdfbox.cos.COSObject.accept(COSObject.java:158) at org.apache.pdfbox.pdfwriter.COSWriter.doWriteObject(COSWriter.java:530) at org.apache.pdfbox.pdfwriter.COSWriter.doWriteObjects(COSWriter.java:459) at org.apache.pdfbox.pdfwriter.COSWriter.doWriteBody(COSWriter.java:443) at org.apache.pdfbox.pdfwriter.COSWriter.visitFromDocument(COSWriter.java:1088) at org.apache.pdfbox.cos.COSDocument.accept(COSDocument.java:419) at org.apache.pdfbox.pdfwriter.COSWriter.write(COSWriter.java:1359) at org.apache.pdfbox.pdfwriter.COSWriter.write(COSWriter.java:1246) at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:1146) {code} I'll precice this issue and reopen it. > ScratchFileBuffer not closed message related to overlay.overlay(overlayGuide); > ------------------------------------------------------------------------------ > > Key: PDFBOX-3612 > URL: https://issues.apache.org/jira/browse/PDFBOX-3612 > Project: PDFBox > Issue Type: Bug > Affects Versions: 2.0.3, 2.1.0 > Environment: Windows 7 Professional, Eclipse, JDK 1.8 > Reporter: André Heuner > Priority: Minor > > I'd like to add a watermark to a PDF and have the following code: > {code:java} > PDDocument pdfDocument = PDDocument.load(new > PDDocument pdfCopy = Pdf.addWatermark(pdfDocument); > > pdfDocument.close(); > pdfCopy.close(); > .... > public static PDDocument addWatermark(PDDocument document) { > try { > HashMap<Integer, String> overlayGuide = new HashMap<Integer, > String>(); > > for(int no = 0; no < document.getNumberOfPages(); no++){ > overlayGuide.put(no +1, "C:\\Software\\watermark.pdf"); > } > > Overlay overlay = new Overlay(); > overlay.setInputPDF(document); > overlay.setOverlayPosition(Overlay.Position.FOREGROUND); > > PDDocument result = overlay.overlay(overlayGuide); > > document.close(); > overlay.close(); > > return result; > > } catch (Exception e) { > log.error("Error while adding watermark: " > +e.getMessage(), e); > > return document; > } > } > {code} > overlay.overlay(...) seems to cause lot's of warnings: > {code} > [2016-12-01-09:48:51] DEBUG [org.apache.pdfbox.io.ScratchFileBuffer] > ScratchFileBuffer not closed! > [2016-12-01-09:48:51] DEBUG [org.apache.pdfbox.io.ScratchFileBuffer] > ScratchFileBuffer not closed! > [2016-12-01-09:48:51] DEBUG [org.apache.pdfbox.io.ScratchFileBuffer] > ScratchFileBuffer not closed! > [2016-12-01-09:48:51] DEBUG [org.apache.pdfbox.io.ScratchFileBuffer] > ScratchFileBuffer not closed! > [2016-12-01-09:48:51] DEBUG [org.apache.pdfbox.io.ScratchFileBuffer] > ScratchFileBuffer not closed! > [2016-12-01-09:48:51] DEBUG [org.apache.pdfbox.io.ScratchFileBuffer] > ScratchFileBuffer not closed! > {code} > Is there anything, that can be done to fix this issue? I tried to close > anything that is closable - but the issue remains. Or can it safely be > ignored? -- This message was sent by Atlassian JIRA (v6.3.4#6332) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@pdfbox.apache.org For additional commands, e-mail: dev-h...@pdfbox.apache.org