Op 5/08/2012 23:21, agha ali schreef: > if i insert the image in pdf in foreach loop as you previously stated > that it will duplicate and it is not a good solution .
Correct, and by creating the Image objects up-front, you can avoid that problem. > but the images may be all distinct or some common , And that's not a problem. > i can find the list of distinct imageName, OK, but please be aware that the images lose their name when you add them to a PDF. The image stream is added as 1 or more objects to the PDF file. They also get a name such as /Img0 when referred to from a page, but that name is unique per page, NOT unique in the document. An Image XObject named /Img0 in page 1 may be totally different from an Image XObject with the same name in page 2. > so what i want is insert the image data in pdf as a resource Er... Bad idea! Bad idea! Bad Idea! This way you could add images to a PDF document that are never used. For instance: you add 20 images because you THINK they are needed, but eventually you may only use 16 of them, resulting in at least 4 objects with possibly large byte streams that are unnecessary. > and use that resource and insert the the specific image (with > loaction and size) in foreach loop. That's EXACTLY what iText does. The moment you add an Image for the first time to a PDF, an id is created internally. Whenever you use the same Image XObject again, the id is reused. If you really insist to implement your design (which is IMHO flawed), you can do so by using the code in section 16.1.1 (page 527) of "iText in Action - Second Edition" (that's in the advanced chapters hardly anybody reads). In that example, a low-level PdfImage object is created (that's an image dictionary), and it's added straight to the writer before the high-level Image object is added to the Document. When the low-level object is added to the writer, it gets a reference that is unknown to the high-level object, so don't forget to set that reference! The four lines in Listing 16.1 from chapter 16, are invoked automatically for you if you use iText correctly, so there's really no need for you to implement your idea. ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions iText(R) is a registered trademark of 1T3XT BVBA. Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/ Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php
