Could we see the stack trace? PS: Your code would be much cleaner if you used PdfDictionary's getAs* methods. They handle the PdfReader.getObject(...) for you as needed.
> > PdfDictionary parent = > (PdfDictionary)reader.getPdfObject(1); Err... bad idea. Never look up objects by Object Number with hard-coded numbers. I realize you may have found the number programmatically, but there's still a better way: PdfDictionary parent = reader.getPageN(1); // for the first page, 1-indexed. > > PdfObject resources = parent.get(PdfName.RESOURCES); > > PdfDictionary resDict = (PdfDictionary) > >PdfReader.getPdfObject(resources); > > PdfObject xobjects = resDict.get(PdfName.XOBJECT); > > PdfDictionary xObjDict = (PdfDictionary) > >PdfReader.getPdfObject(xobjects); PdfDictionary restDict = parent.getAsDict(PdfName.RESOURCES); PdfDictionary xObjDict = resDict.getAsDict(PdfName.XOBJECT); The getAs* functions (PdfArray has a matching set) will return a null if the element is missing or if it's the wrong type. If you need to know which, you need extra code (such as the Old Method). And they automagically look up indirect references and check their type too. Not that it helps you with your problem. Err... I cannot find a "NullReferenceException" anywhere within iText. So I'd /really/ like to see that stack trace. --Mark Storer Senior Software Engineer Cardiff.com import legalese.Disclaimer; Disclaimer<Cardiff> DisCard = null; > -----Original Message----- > From: Felipe Roos [mailto:feliper...@yahoo.com] > Sent: Wednesday, July 14, 2010 7:59 AM > To: Post all your questions about iText here > Subject: [iText-questions] Res: Adding a PdfImportedPage into a > xobjectPdfDictionary - is this a good thing to do? > > Any update on this? > > Felipe Roos > http://www.linkedin.com/in/feliperoos > > > Achar desculpas para os nossos > defeitos não nos torna melhores > > > > ----- Mensagem original ---- > > De: Felipe Roos <feliper...@yahoo.com> > > Para: Post all your questions about iText here > ><itext-questions@lists.sourceforge.net> > > Enviadas: Quinta-feira, 10 de Junho de 2010 14:02:56 > > Assunto: Re: [iText-questions] Adding a PdfImportedPage into a xobject > >PdfDictionary - is this a good thing to do? > > > > > > 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 > > iText-questions@lists.sourceforge.net > > 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/ > > > > > > > -------------------------------------------------------------------------- > ---- > This SF.net email is sponsored by Sprint > What will you do first with EVO, the first 4G phone? > Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first > _______________________________________________ > iText-questions mailing list > iText-questions@lists.sourceforge.net > 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/ > > > No virus found in this incoming message. > Checked by AVG - www.avg.com > Version: 9.0.830 / Virus Database: 271.1.1/3003 - Release Date: 07/13/10 > 11:36:00 ------------------------------------------------------------------------------ This SF.net email is sponsored by Sprint What will you do first with EVO, the first 4G phone? Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first _______________________________________________ iText-questions mailing list iText-questions@lists.sourceforge.net 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/