In general, unit testing PDF is all but impossible. You really need to visually inspect the output.
As to your specific question, "where's my image?": 1: You need to know the resource name of the image in question. If there's only one XObject Image and no XObject Form[s], you can simply latch onto the first "Do" command you run into. If not... you need to hunt down the right image... which may be burried in an XObject Form's resources which can be burried in an XObject Form's resources... which can be... I think you get the idea. 2: You need to determine the Current Transformation Matrix at the time the image is drawn. com.cardiff.lowagie.pdf.parser.PdfContentStreamParser will get you most of the way there, but NOT ALL. It doesn't recurse into XObject Forms (and it probably should on general principle). When you locate the correct "/MyResName Do" call, you need to peek() at the current GraphicsState and get its Matrix. Which is package private. Huh. Well, if you're hacking up PdfContentStreamParser, you might as well tweak that too. Oh, and in the general case, you need to check the page rotation and take that into account as well. --Mark Storer Senior Software Engineer Cardiff.com #include <disclaimer> typedef std::Disclaimer<Cardiff> DisCard; > -----Original Message----- > From: Larry Reeder [mailto:lnree...@gmail.com] > Sent: Friday, November 20, 2009 7:31 AM > To: Post all your questions about iText here > Subject: [iText-questions] How to find the position of an image in a > PDFfile? > > > Sorry to the list if you see this question twice. I previously posted > this message yesterday, but hasn't shown up on the list yet, so I'll > try it again. > > I've used the iText Java API to create a PDF with several images. Now > I'd like to write a unit test to verify my image placement logic. I > used Image.setAbsolutePosition to set the image when I initially > created the PDF. Now how do I get the position of that image when I > reopen the PDF? I know I can get the height and width of > images with something like this: > > PdfReader pdfReader = new PdfReader("mytestdoc.pdf"); > > for (int i = 0; i < reader.getXrefSize(); i++) > { > PdfObject pdfobj = reader.getPdfObject(i); > > if (pdfobj != null && pdfobj.isStream()) > { > PdfStream stream = (PdfStream) pdfobj; > PdfObject pdfsubtype = stream.get(PdfName.SUBTYPE); > if (pdfsubtype != null && > PdfName.IMAGE.toString().equals(pdfsubtype.toString())) > { > int height = ((PdfNumber) > stream.get(PdfName.HEIGHT)).intValue(); > int width = ((PdfNumber) > stream.get(PdfName.WIDTH)).intValue(); > > System.err.println("image width/height: " + > width + ","+ height); > } > > } > > } > > > But how do I find the "x" and "y" of the image? > > > Thanks.............. Larry > > -------------------------------------------------------------- > ---------------- > Let Crystal Reports handle the reporting - Free Crystal > Reports 2008 30-Day > trial. Simplify your report design, integration and > deployment - and focus on > what you do best, core application coding. Discover what's new with > Crystal Reports now. http://p.sf.net/sfu/bobj-july > _______________________________________________ > iText-questions mailing list > iText-questions@lists.sourceforge.net > 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/ ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ iText-questions mailing list iText-questions@lists.sourceforge.net 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/