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

Close all COSStreams when creating a new pdf

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.0
    • Fix Version/s: 2.0.0
    • Component/s: PDModel
    • Labels:
      None

      Description

      Peter Prusinowski posted on users@ that he got a lot of debug warnings about COSStreams which are not closed. He provided the following code to reproduce the effect:

          public static void generate() throws IOException {
              PDDocument doc = new PDDocument();
      
              try {
                  PDPage page = new PDPage();
                  doc.addPage(page);
                  PDPageContentStream content = new PDPageContentStream(doc, page);
                  BufferedImage bi = ImageIO.read(new File("/tmp/test.png"));
                  PDImageXObject img = LosslessFactory.createFromImage(doc, bi);
                  content.drawImage(img, 0, 0);
                  content.close();
              } finally {
                  if (doc != null) {
                      doc.save("/tmp/testPdf.pdf");
                      doc.close();
                  }
              }
          }
      
          public static void main(String[] args) throws IOException {
              generate();
              generate();
              generate();
          }
      

      I've got the same warnings using that specific code.

        Attachments

          Activity

            People

            • Assignee:
              lehmi Andreas Lehmkühler
              Reporter:
              lehmi Andreas Lehmkühler
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: