Uploaded image for project: 'PDFBox'
  1. PDFBox
  2. PDFBOX-4294

Scratch file already closed when redoing overlay

Attach filesAttach ScreenshotAdd voteVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.0.11
    • None
    • Utilities

    Description

      Here's some sample code to reproduce the problem:

       

      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);
      

      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.

       

      Attachments

        1. overlay-v2.zip
          6 kB
          Adrian Sándor
        2. overlay.zip
          6 kB
          Adrian Sándor
        3. MyOverlay.java
          8 kB
          Adrian Sándor

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            Unassigned Unassigned
            aditsu Adrian Sándor

            Dates

              Created:
              Updated:

              Slack

                Issue deployment