1T3XT info wrote:
> Your requirement calls for a Proof of Concept in the form
of an interesting
> example on itextpdf.com. Maybe you can
already start and share this example.
> If it doesn't work,
I'll take a look at it after work.
I tried the following code:
//A file containing an image xobject named /Im0
PdfReader reader = new PdfReader(/*somefile.pdf*/);
//A 1-page file to be added into the original file
PdfReader fileToAdd = new PdfReader (/*someotherfile.pdf*/);
PdfStamper stamper = new PdfStamper(reader, new
FileOutputStream(args[2]));
//The name of the entry in the xobject dictionary
PdfName name = new PdfName("Im0");
//The page object where that image is
PdfDictionary parent = (PdfDictionary)reader.getPdfObject(1);
PdfObject resources = parent.get(PdfName.RESOURCES);
PdfDictionary resDict = (PdfDictionary)
PdfReader.getPdfObject(resources);
PdfObject xobjects = resDict.get(PdfName.XOBJECT);
PdfDictionary xObjDict = (PdfDictionary)
PdfReader.getPdfObject(xobjects);
//import the first page of the fileToAdd
PdfImportedPage page = stamper.getImportedPage(fileToAdd,1);
//following
http://itextpdf.com/examples/index.php?page=example&id=285 sample
Image img = Image.getInstance(page);
PdfImage pdfImage = new PdfImage(img, "", null);
PdfIndirectObject imgRef = stamper.getWriter().addToBody(pdfImage);
xObjDict.put(name, imgRef.getIndirectReference());
stamper.close();
Using Itext 2.1.7, it crashes in the creation of the PdfImage object with a
NullReferenceException.
BTW, thanks in advance for you support on this.
Regards,
Felipe Roos
------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the
lucky parental unit. See the prize list and enter to win:
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
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/