Dear Mr Bruno,
i'm trying to convert image from PDF to Pict File
PdfReader reader = new PdfReader(srcFile);
int total_number_of_pictures = 0;
for (int i = 0; i < reader.getXrefSize(); i++) {
PdfObject pdfobj = reader.getPdfObject(i);
if (pdfobj != null) {
if (pdfobj.isStream()) {
PdfStream pdfdict = (PdfStream)
pdfobj;
PdfObject pdfsubtype = pdfdict
.get(PdfName.SUBTYPE);
if (pdfsubtype == null) {
continue;
}
if (!pdfsubtype.toString().equals(
PdfName.IMAGE.toString())) {
continue;
}
System.out.println("total_number_of_pictures: "+
total_number_of_pictures);
System.out.println("height:"+pdfdict.get(PdfName.HEIGHT));
System.out.println("width:"+
pdfdict.get(PdfName.WIDTH));
System.out.println("bitspercomponent:"+pdfdict.get(PdfName.BITSPERCOMPONENT));
byte[] barr =
PdfReader.getStreamBytesRaw((PRStream)pdfdict);
java.awt.Image im =
Toolkit.getDefaultToolkit().createImage(barr);
BufferedImage img = new
BufferedImage(300,300,BufferedImage.TYPE_INT_ARGB);
Graphics graph = img.getGraphics();
graph.drawImage(im,100,100,null);
FileOutputStream os = new
FileOutputStream("test"+total_number_of_pictures+".jpg");
ImageIO.write(img,"JPEG",os);
os.close();
total_number_of_pictures++;
}
}
}
this is my code, but the result is blank pict (black), is my code is wrong ?
which one is wrong ?
Thanks
Bruno Lowagie (iText) wrote:
>
> Gunawan Candra wrote:
>> How can I get raw ByteStream for image in PDF ?
>
> So you have an existing PDF and you want to grab the bytes
> of an Image? OK, then you could find some inspiration in
> the iText toolbox: http://itexttoolbox.sourceforge.net/
>
> There's a plug-in called ImageXRefViewer and if you look
> at its execute() method, you'll discover one way to get
> the PDF object that has the stream with the image bytes:
> http://itexttoolbox.svn.sourceforge.net/viewvc/itexttoolbox/main/src/com/lowagie/tools/plugins/ImageXRefViewer.java?revision=110&view=markup
>
>> How can I get the type of raw bytestream (JPEG/ TIFF/ PNG/) for image in
>> PDF ?
>
> Hmm... it's not because you add an image of a certain type to
> a PDF that this image will keep that same type.
> Maybe you should read the PDF reference (available as a free
> download on adobe.com) to have a better understanding about
> images in PDF.
>
>> Can i-text convert / grab image from PDF file ?
>
> Grab: yes; convert: it depends.
> See my first answer, find out how ImageXRefViewer works.
>
>> Can i-text resize image (I mean, resize the physically file) from PDF ?
>
> No; iText doesn't reduce the quality/filesize of images;
> you'll need something like JAI to do this.
> br,
> Bruno
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc.
> Still grepping through log files to find problems? Stop.
> Now Search log events and configuration files using AJAX and a browser.
> Download your FREE copy of Splunk now >> http://get.splunk.com/
> _______________________________________________
> 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/
>
>
--
View this message in context:
http://www.nabble.com/Get-ByteStream-tf4690732.html#a13425013
Sent from the iText - General mailing list archive at Nabble.com.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
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/