Hello All 

Recently a request was made to update PdfGraphics2D using Java's ImageIO
library instead of relying on com.sun classes.

I have made the updates and included them below.

My apologies for the format of this patch, I am unaccustomed to submitting
code.
 
Below are the relevent changes:

Line #180

        super();

        /*
        *  Below can be safely removed
        */

      /*try {
        Class.forName("com.sun.image.codec.jpeg.JPEGCodec");
      }
      catch (Throwable t) {
        convertImagesToJPEG = false;
      }*/
 
Line # 1257
 
        BufferedImage scaled = new BufferedImage(img.getWidth(null),
img.getHeight(null), BufferedImage.TYPE_INT_RGB);
        Graphics2D g3 = scaled.createGraphics();
        g3.setColor(Color.WHITE);
        g3.fillRect(0,0,img.getWidth(null), img.getHeight(null));
        g3.drawImage(img, 0, 0, img.getWidth(null), img.getHeight(null),
null);  
        g3.dispose();   
        img.flush();
        img = null;

        ByteArrayOutputStream baos = new ByteArrayOutputStream();


        /*
        *  Below comments can be safely removed
        */

        /*com.sun.image.codec.jpeg.JPEGImageEncoder encoder =
com.sun.image.codec.jpeg.JPEGCodec.createJPEGEncoder(baos);
        com.sun.image.codec.jpeg.JPEGEncodeParam param =
com.sun.image.codec.jpeg.JPEGCodec.getDefaultJPEGEncodeParam(scaled);
        param.setQuality(jpegQuality, true);
        encoder.encode(scaled, param);*/

        /*
        *  End removal
        */

        ImageWriteParam iwparam = new
JPEGImageWriteParam(Locale.getDefault());
        iwparam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
        iwparam.setCompressionQuality(jpegQuality);//Set here your
compression rate
        ImageWriter iw = ImageIO.getImageWritersByFormatName("jpg").next();
        ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
        iw.setOutput(ios);
        iw.write(null, new IIOImage(scaled, null, null), iwparam);
        iw.dispose();
        ios.close();

        scaled.flush();
        scaled = null;
        image = com.lowagie.text.Image.getInstance(baos.toByteArray());
        baos.flush();
        baos.close();


Sincerely, 

Bill Ensley
Phone: 503.244.4738
Fax: 503.244.5235

 <http://www.bearprinting.com> 
________________________________

P.S. If you aren't able to open the photo proof, 
you may not have Adobe Acrobat Reader
<http://www.adobe.com/products/acrobat/readstep2.html> . You can download it
for free from: 
http://www.adobe.com/products/acrobat/readstep2.html 


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/

Reply via email to