You are assuming that PDF maintains the PNG nature of the image - that is NOT the case. PDF only supports two kinds of images JPEG (which is why this works) and "raw bitmaps" (aka an array of bits). So in your case, with the PNG, it is transcoded into the latter case and so if you want it back you will need to reverse the process on your end.
-----Original Message----- From: [email protected] [mailto:[email protected]] Sent: Monday, February 22, 2010 2:52 PM To: [email protected] Subject: [iText-questions] Using Images extracted from a pdf hi, sry for a bad english.. i working for better that. i need a big help.. I managed with the help of tutorials and codes of this mail list, insert and extract images from a PDF. the problem is when I insert an image in PNG format and then try to get the same... on here i make insert... my file is an image whit PNG encode . [code] com.lowagie.text.Image img = com.lowagie.text.Image.getInstance(f.toURL()); if(img != null) { document.setPageSize(new Rectangle(img.getScaledWidth(), img.getScaledHeight())); document.newPage(); img.setAbsolutePosition(0, 0); cb.addImage(img); } [/code] on here i try to take that image... [code] int XrefIndex =((PRIndirectReference)obj).getNumber(); PdfObject pdfObj = pdf.getPdfObject(XrefIndex); PdfStream pdfStrem = (PdfStream)pdfObj; byte[] bytes = PdfReader.getStreamBytesRaw((PRStream)pdfStrem); if ((bytes != null)) { String fileName = "Image_P"+pageNumber+"_"; File file = new File(fileName); FileOutputStream fw = new FileOutputStream(file); fw.write(bytes); fw.flush(); fw.close(); BufferedImage img2 = ImageIO.read(file); com.lowagie.text.Image img = com.lowagie.text.Image.getInstance(file.toURL()); } [/code] img2 returned a null !!!! in line of img .. has a Excpetion "Image_P1_ is not a recognized imageformat" when i try to do : [code] Image image = Toolkit.getDefaultToolkit().createImage(bytes); [code] and before create an image from this image getting the width and height from my PdfStream (create a buffered and draw the image) when i serialize on a file and visualize this.. this image in a fucking black picture .. all black -.- if i use JPEG encode for my images.. all the 3 solution i have .. its ok.. have effects.. i can vizualize my images how to i create then .. perfect.. but if i change de JPEG ... for any other encode.. thats not have efect .. can any help-me plz ? -- This message was sent on behalf of [email protected] at openSubscriber.com http://www.opensubscriber.com/messages/[email protected]/topic.html ------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev _______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://www.1t3xt.com/docs/book.php Check the site with examples before you ask questions: http://www.1t3xt.info/examples/ You can also search the keywords list: http://1t3xt.info/tutorials/keywords/ ------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev _______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://www.1t3xt.com/docs/book.php Check the site with examples before you ask questions: http://www.1t3xt.info/examples/ You can also search the keywords list: http://1t3xt.info/tutorials/keywords/
