0 Replies Latest reply on Sep 1, 2006 3:34 PM by LenderDesign

    Help with iText code

    LenderDesign Level 1
      Honestly, I know very little about iText and how to use it. I'm also a novice at CF. I have been searching for a way to change the image of a button in an existing PDF file. I found a code sample, but it's all over my head.

      If someone can help me get it to work in CF, I would greatly appreciate it:

      PdfReader pdf = new PdfReader("in.pdf");
      PdfStamper stp = new PdfStamper(pdf, new FileOutputStream("out.pdf"));
      PdfWriter writer = stp.getWriter();
      Image img = Image.getInstance("image.png");
      AcroFields af = stp.getAcroFields();
      AcroFields.Item item = af.getFieldItem("Button1");
      PdfDictionary dic = (PdfDictionary)item.widgets.get(0);
      dic = (PdfDictionary)PdfReader.getPdfObject(dic.get(PdfName.AP));
      dic = (PdfDictionary)PdfReader.getPdfObject(dic.get(PdfName.N));
      dic = (PdfDictionary)PdfReader.getPdfObject(dic.get(PdfName.RESOURCES));
      dic = (PdfDictionary)PdfReader.getPdfObject(dic.get(PdfName.XOBJECT));
      dic = (PdfDictionary)PdfReader.getPdfObject(dic.get(PdfName.FRM));
      dic = (PdfDictionary)PdfReader.getPdfObject(dic.get(PdfName.RESOURCES));
      dic = (PdfDictionary)PdfReader.getPdfObject(dic.get(PdfName.XOBJECT));
      PdfObject obj = dic.get((PdfName)dic.getKeys().iterator().next());
      if (obj.isIndirect()) {
      PdfDictionary tg = (PdfDictionary)PdfReader.getPdfObject(obj);
      PdfName type =
      if (PdfName.IMAGE.equals(type)) {
      Image maskImage = img.getImageMask();
      if (maskImage != null)
      writer.addDirectImageSimple(img, (PRIndirectReference)obj);