Hi,

I wasn't too happy with the quality of the generated PDF, especially because I am generating the PDF from images, so I did play a little bit with PDJpeg

In public PDJpeg(PDDocument doc, BufferedImage bi) throws IOException {

I did replace :

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

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


The quality is much better. I think by default the compression quality is 0.75 The PDF file is bigger. So maybe we could have a global parameter to set the desired quality, and use it in iwparam.setCompressionQuality(1.0f);


Hope this help and which that change can be integrated.

Thanks,

Olivier DOREMIEUX

Reply via email to