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

Blank line/dot appears when converting PDF to PNG

    XMLWordPrintableJSON

Details

    Description

      I have the following test:

      @Test
      public void testPDFBoxBug() throws IOException

      { ClassLoader classLoader = getClass().getClassLoader(); File file = new File(classLoader.getResource("PdfBox_Test.pdf").getFile()); byte[] bytes = Files.readAllBytes(file.toPath()); convertPDFToPNG(bytes); }

      private List<String> convertPDFToPNGLight(byte[] input) throws IOException {
      List<String> convertedPNGs = new ArrayList<>();
      PDDocument doc = PDDocument.load(input);
      PDFRenderer renderer = new PDFRenderer(doc);

      for(int i = 0; i < doc.getNumberOfPages() ; i++) {
      BufferedImage img = null;
      img = renderer.renderImageWithDPI(i, 96);

      ByteArrayOutputStream out2 = new ByteArrayOutputStream();

      ImageIO.write(img, "PNG", out2);

      out2.size();

      convertedPNGs.add(Base64Utils.encodeToString(out2.toByteArray()));
      try (OutputStream outputStream = new FileOutputStream("target/thefilename" + i + ".png"))

      { out2.writeTo(outputStream); }

      }
      doc.close();
      return convertedPNGs;
      }

       

      My input and output are in attachment.

      Attachments

        1. PdfBox_Test.pdf
          412 kB
          Luppens Patrice
        2. thefilename0.png
          264 kB
          Luppens Patrice

        Issue Links

          Activity

            People

              Unassigned Unassigned
              luppensp Luppens Patrice
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: