[ 
https://issues.apache.org/jira/browse/PDFBOX-4294?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16596732#comment-16596732
 ] 

Adrian Sándor commented on PDFBOX-4294:
---------------------------------------

Ok, I'm not familiar with the internal structure of documents in pdfbox, I only 
saw the contents being modified. I looked for any changes to resources now, and 
I found a likely modification in only one place - createOverlayXObject. I can 
try to save/restore the resources too, I'll probably give you an updated 
version.

The main point of my 2nd attachment is that I refactored the Overlay class to 
use my code while keeping its own API 100% identical. And the modified Overlay 
class doesn't use the "save original" feature. About reopening the PDF, well, 
I'd like to be able to do as many overlays per second as possible, so every 
little thing matters.

> Scratch file already closed when redoing overlay
> ------------------------------------------------
>
>                 Key: PDFBOX-4294
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-4294
>             Project: PDFBox
>          Issue Type: Bug
>          Components: Utilities
>    Affects Versions: 2.0.11
>            Reporter: Adrian Sándor
>            Priority: Major
>         Attachments: MyOverlay.java, overlay.zip
>
>
> Here's some sample code to reproduce the problem:
>  
> {code:java}
> final String path = "orig.pdf";
> final String stampPath = "stamp.pdf";
> final PDDocument doc = PDDocument.load(new File(path));
> final Overlay o = new Overlay();
> o.setInputPDF(doc);
> o.setOverlayPosition(Position.FOREGROUND);
> final HashMap<Integer, String> m = new HashMap<>();
> m.put(0, stampPath);
> PDDocument res = o.overlay(m);
> res.close();
> res = o.overlay(m);
> {code}
> Basically I'm doing an overlay, closing the resulting document, then doing it 
> again (normally I would make some changes first, but I didn't include that 
> for the sake of brevity).
> The last line throws java.io.IOException: Scratch file already closed
> If I remove "res.close()" then the code works, but if I do the overlay 
> multiple times, I get warnings like: org.apache.pdfbox.cos.COSDocument - 
> Warning: You did not close a PDF Document
> which suggests that I should actually close the document when I'm done with 
> it.
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to