[EMAIL PROTECTED] wrote:
> Hello
> My English ability is very poor. sorry
> I want to read a pdf file
> and save image to file
> I try but..
> for (int i = 0; i < reader.getXrefSize(); i++) 
>             { 
>             PdfObject pdfobj = reader.getPdfObject(i); 
> }
> 
> first I read file
> and then getPdfObject...

Not every object in a PDF is an image.
Images are stored in PDF objects of type stream,
but not all streams are images, so once you
have your pdfobj, you need to do the following checks:

if (!pdfobj.isStream()) {
     throw new Exception("Not a stream");
}
PdfStream stream = (PdfStream) pdfobj;
PdfObject pdfsubtype = streal.get(PdfName.SUBTYPE);
if (pdfsubtype == null) {
     throw new Exception("Not an image stream");
}
if (!pdfsubtype.toString().equals(PdfName.IMAGE.toString())) {
     throw new Exception("Not an image stream");
}               
// now you have a PDF stream object with an image
byte[] img = PdfReader.getStreamBytesRaw((PRStream) stream);
// but you don't know anything about the image format.
// you'll have to get info from the stream dictionary
System.out.println("height:" + stream.get(PdfName.HEIGHT));
System.out.println("width:" + stream.get(PdfName.WIDTH));                
System.out.println("bitspercomponent:" +
     stream.get(PdfName.BITSPERCOMPONENT));
...             
// or you could try making a java.awt.Image from the array:
java.awt.Image i = Toolkit.getDefaultToolkit().createImage(img);

In any case, it's not as simple as you would think.
br,
Bruno

-------------------------------------------------------------------------
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
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/

Reply via email to