breegee wrote > I am trying to replace a particular image on several pages in a pdf. It > runs through the code fine but when I open the file I see the first image > replaced and when I scroll to the second page it says there is an error in > the pdf.
Unfortunately you did not share your PDF, so one has to guess a bit. Two possible reasons: * The same image object is referenced from page 1 and page 2. Your code replaces the reference on page one and kills the object. On page two your code does nothing to the image reference as (due to your killing the image object before) the reference goes to null. The PDF viewer later, when trying to display page two, finds this image reference pointing nowhere and complains. * You use "pdfStamper.Writer.CloseStream = False", thus "pdfStamper.Close()" does not implicitly close your stream. I also don't see you explicitly closing that stream. Depending on the circumstances this might indeed result in a damaged result file (the CloseStream flag predominantly is intended for use with MemoryStreams, not with FileStreams; due to buffering FileStreams may behave funny if not closed.) Regards, Michael -- View this message in context: http://itext.2136553.n4.nabble.com/Replace-images-in-pdf-tp4660966p4660967.html Sent from the iText mailing list archive at Nabble.com. ------------------------------------------------------------------------------ _______________________________________________ iText-questions mailing list iText-questions@lists.sourceforge.net 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