An image's DPI has to do with its width/height in pixels and its
width/height on the page. ImageObject has no idea how that image is
drawn. I suspect the getDPI call is only supported for a couple
different formats.
At any rate, to determine the size of an image on the page, you need to
know the Current Transformation Matrix (ctm) at the time it was drawn.
To do this, you need to use the classes in the pdf.parser package. Do
we have an example of its use floating around anywhere?
--Mark Storer
Senior Software Engineer
Cardiff.com
import legalese.Disclaimer;
Disclaimer<Cardiff> DisCard = null;
________________________________
From: Naz B [mailto:[email protected]]
Sent: Wednesday, August 18, 2010 2:30 PM
To: [email protected]
Subject: [iText-questions] Attempting to read the DPI of images
in a PDF
Hello,
I have browsed the archives and am still stumped. I am trying to
verify that the DPI of images in a PDF are within a certain range. I
have no control or knowledge of how the PDF was created. I found and ran
the following code snippet:
PdfReader chartReader = new
PdfReader(fileName);
int size = chartReader.getXrefSize();
for (int i = 0; i <
chartReader.getXrefSize(); i++) {
PdfObject pdfobj =
chartReader.getPdfObject( i );
if (pdfobj != null &&
pdfobj.isStream()) {
PdfStream stream = (PdfStream)
pdfobj;
PdfObject pdfsubtype =
stream.get(PdfName.SUBTYPE);
//System.out.println("Stream
subType: " + pdfsubtype);
if (pdfsubtype != null &&
pdfsubtype.toString().equals(PdfName.IMAGE.toString())) {
byte[] image =
PdfReader.getStreamBytesRaw((PRStream) stream);
String
filter=stream.get(PdfName.FILTER).toString();
int width =
Integer.parseInt((stream.get(PdfName.WIDTH)).toString());
int height =
Integer.parseInt((stream.get(PdfName.HEIGHT)).toString());
int bpc =
Integer.parseInt((stream.get(PdfName.BITSPERCOMPONENT)).toString());
System.out.println("Height"
+ height);
System.out.println("Width" +
width);
Image imageObject =
Image.getInstance(image);
System.out.println("ResolutionX: " + imageObject.getDpiX());
System.out.println("ResolutionY: " + imageObject.getDpiX());
}
}
}
The height and width (in pixels) are reported accurately
(verified via checking the images in the pdf in Acrobat Professional).
However, the dpiX and dpiY are always 0 (they shouldn't be as per
Acrobat Professional. ). Any ideas as to why this is the case? Thank
you.
No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 9.0.851 / Virus Database: 271.1.1/3068 - Release Date:
08/17/10 23:35:00
------------------------------------------------------------------------------
This SF.net email is sponsored by
Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://www.itextpdf.com/book/
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/