Hello, I'm investigating using this library to strip images out of PDFs and replace with different images that also link to a webpage (explaining why the images have been replaced).
I have successfully compiled some sample code used to strip images from a PDF. However, when I open the PDF in Acrobat Pro, I get the following two errors: 1) When the first page that had an image replaced is scrolled into view: "Could not find XObject named 'Im0'"; 2) When the next page that had an image replaced is scrolled into view: "An error exists on this page. Acrobat may not display the page correctly. Please contact the person who created the PDF document to correct the problem." The version of Acrobat I am using is: Adobe Acrobat 8 Professional (8.1.2) My code is: import java.io.*; import java.util.*; import com.lowagie.text.*; import com.lowagie.text.pdf.*; public class itexttest{ public static void main(String[] args){ try{ PdfReader pdf = new PdfReader(args[0]); PdfStamper stp = new PdfStamper(pdf, new FileOutputStream(args[1])); PdfWriter writer = stp.getWriter(); Image img = Image.getInstance("image.png"); for(int i = 1, l = pdf.getNumberOfPages(); i <= l; i++){ PdfDictionary pg = pdf.getPageN(i); if(pg == null){ System.out.println("PDFD null"); continue; } PdfDictionary res = (PdfDictionary)PdfReader.getPdfObject(pg.get(PdfName.RESOURCES)); PdfDictionary xobj = (PdfDictionary)PdfReader.getPdfObject(res.get(PdfName.XOBJECT)); if (xobj != null) { for (Iterator it = xobj.getKeys().iterator(); it.hasNext(); ) { PdfObject obj = xobj.get((PdfName)it.next()); if (obj.isIndirect()) { PdfDictionary tg = (PdfDictionary)PdfReader.getPdfObject(obj); PdfName type = (PdfName)PdfReader.getPdfObject(tg.get(PdfName.SUBTYPE)); if(PdfName.IMAGE.equals(type)) { PdfReader.killIndirect(obj); Image maskImage = img.getImageMask(); if (maskImage != null) writer.addDirectImageSimple(maskImage); writer.addDirectImageSimple(img, (PRIndirectReference)obj); //break; } } } } } stp.close(); }catch(Exception e){ System.out.println("Error: " + e.toString()); } } } If it helps, the lines: if (maskImage != null) writer.addDirectImageSimple(maskImage); are useless, because for some reason maskImage is always null. Can anyone help me with my task here? Thanks! ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ 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