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

Image quality improvements

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.4.0
    • 1.5.0
    • PDModel
    • None

    Description

      The quality of the images inserted in a PDF documents could be improved by changing PDJpeg.java
      In the API
      public PDJpeg(PDDocument doc, BufferedImage bi) throws IOException

      ImageIO.write(bi, "jpeg", os);

      could be replaced by :

      ImageWriter writer = null;
      Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
      if (iter.hasNext())

      { writer = (ImageWriter) iter.next(); }

      ImageOutputStream ios = ImageIO.createImageOutputStream(os);
      writer.setOutput(ios);

      // Set the compression quality
      JPEGImageWriteParam iwparam = new JPEGImageWriteParam(Locale.getDefault());
      iwparam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
      iwparam.setCompressionQuality(1.0f);

      // Write the image
      writer.write(null, new IIOImage(bi, null, null), iwparam);

      writer.dispose();

      This increase the size of the generated PDF.
      By default the JPEG quality is 0.75, in the patch I use 1.0, the maximum quality
      As a suggestion the quality of the JPEG could be a global variable since it affect the size of the PDF

      Attachments

        1. PDJpeg.patch
          2 kB
          Olivier DOREMIEUX

        Activity

          People

            lehmi Andreas Lehmkühler
            odoremieux Olivier DOREMIEUX
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: