@SuppressWarnings("unchecked")
 void mergeField(String name, AcroFields.Item item) {
   HashMap<String, Object> map = fieldTree;
   StringTokenizer tk = new StringTokenizer(name, ".");
   if (!tk.hasMoreTokens()) return;
   while (true) {
     String s = tk.nextToken();
     Object obj = map.get(s);
     if (tk.hasMoreTokens()) {
       if (obj == null) {
         obj = new HashMap();
         map.put(s, obj);
         map = (HashMap<String, Object>) obj;
         continue;
       } else if (obj instanceof HashMap) map = (HashMap<String, Object>) obj;
       else return;
     } else {
       if (obj instanceof HashMap) return;
       PdfDictionary merged = item.getMerged(0);
       if (obj == null) {
         PdfDictionary field = new PdfDictionary();
         if (PdfName.SIG.equals(merged.get(PdfName.FT))) hasSignature = true;
         for (Object element : merged.getKeys()) {
           PdfName key = (PdfName) element;
           if (fieldKeys.containsKey(key)) field.put(key, merged.get(key));
         }
         ArrayList<Object> list = new ArrayList<Object>();
         list.add(field);
         createWidgets(list, item);
         map.put(s, list);
       } else {
         ArrayList<Object> list = (ArrayList<Object>) obj;
         PdfDictionary field = (PdfDictionary) list.get(0);
         PdfName type1 = (PdfName) field.get(PdfName.FT);
         PdfName type2 = (PdfName) merged.get(PdfName.FT);
         if (type1 == null || !type1.equals(type2)) return;
         int flag1 = 0;
         PdfObject f1 = field.get(PdfName.FF);
         if (f1 != null && f1.isNumber()) flag1 = ((PdfNumber) f1).intValue();
         int flag2 = 0;
         PdfObject f2 = merged.get(PdfName.FF);
         if (f2 != null && f2.isNumber()) flag2 = ((PdfNumber) f2).intValue();
         if (type1.equals(PdfName.BTN)) {
           if (((flag1 ^ flag2) & PdfFormField.FF_PUSHBUTTON) != 0) return;
           if ((flag1 & PdfFormField.FF_PUSHBUTTON) == 0
               && ((flag1 ^ flag2) & PdfFormField.FF_RADIO) != 0) return;
         } else if (type1.equals(PdfName.CH)) {
           if (((flag1 ^ flag2) & PdfFormField.FF_COMBO) != 0) return;
         }
         createWidgets(list, item);
       }
       return;
     }
   }
 }
Beispiel #2
0
  /**
   * Translate a PRDictionary to a PdfDictionary. Also translate all of the objects contained in it.
   */
  protected PdfDictionary copyDictionary(PdfDictionary in)
      throws IOException, BadPdfFormatException {
    PdfDictionary out = new PdfDictionary();
    PdfObject type = PdfReader.getPdfObjectRelease(in.get(PdfName.TYPE));

    for (Iterator it = in.getKeys().iterator(); it.hasNext(); ) {
      PdfName key = (PdfName) it.next();
      PdfObject value = in.get(key);
      // System.out.println("Copy " + key);
      if (type != null && PdfName.PAGE.equals(type)) {
        if (!key.equals(PdfName.B) && !key.equals(PdfName.PARENT)) out.put(key, copyObject(value));
      } else out.put(key, copyObject(value));
    }
    return out;
  }
 public void setWidget(Rectangle rect, PdfName highlight) {
   put(PdfName.TYPE, PdfName.ANNOT);
   put(PdfName.SUBTYPE, PdfName.WIDGET);
   put(PdfName.RECT, new PdfRectangle(rect));
   annotation = true;
   if (highlight != null && !highlight.equals(HIGHLIGHT_INVERT)) put(PdfName.H, highlight);
 }
 void propagate(PdfObject obj, PdfIndirectReference refo, boolean restricted) throws IOException {
   if (obj == null) return;
   //        if (refo != null)
   //            addToBody(obj, refo);
   if (obj instanceof PdfIndirectReference) return;
   switch (obj.type()) {
     case PdfObject.DICTIONARY:
     case PdfObject.STREAM:
       {
         PdfDictionary dic = (PdfDictionary) obj;
         for (PdfName key : dic.getKeys()) {
           if (restricted && (key.equals(PdfName.PARENT) || key.equals(PdfName.KIDS))) continue;
           PdfObject ob = dic.get(key);
           if (ob != null && ob.isIndirect()) {
             PRIndirectReference ind = (PRIndirectReference) ob;
             if (!setVisited(ind) && !isPage(ind)) {
               PdfIndirectReference ref = getNewReference(ind);
               propagate(PdfReader.getPdfObjectRelease(ind), ref, restricted);
             }
           } else propagate(ob, null, restricted);
         }
         break;
       }
     case PdfObject.ARRAY:
       {
         // PdfArray arr = new PdfArray();
         for (Iterator<PdfObject> it = ((PdfArray) obj).listIterator(); it.hasNext(); ) {
           PdfObject ob = it.next();
           if (ob != null && ob.isIndirect()) {
             PRIndirectReference ind = (PRIndirectReference) ob;
             if (!isVisited(ind) && !isPage(ind)) {
               PdfIndirectReference ref = getNewReference(ind);
               propagate(PdfReader.getPdfObjectRelease(ind), ref, restricted);
             }
           } else propagate(ob, null, restricted);
         }
         break;
       }
     case PdfObject.INDIRECT:
       {
         throw new RuntimeException(
             MessageLocalization.getComposedMessage("reference.pointing.to.reference"));
       }
   }
 }
Beispiel #5
0
  /**
   * merge field attributes from two dictionaries
   *
   * @param parent one dictionary
   * @param child the other dictionary
   * @return a merged dictionary
   */
  protected PdfDictionary mergeAttrib(PdfDictionary parent, PdfDictionary child) {
    PdfDictionary targ = new PdfDictionary();
    if (parent != null) targ.putAll(parent);

    for (Iterator it = child.getKeys().iterator(); it.hasNext(); ) {
      PdfName key = (PdfName) it.next();
      if (key.equals(PdfName.DR)
          || key.equals(PdfName.DA)
          || key.equals(PdfName.Q)
          || key.equals(PdfName.FF)
          || key.equals(PdfName.DV)
          || key.equals(PdfName.V)
          || key.equals(PdfName.FT)
          || key.equals(PdfName.F)) {
        targ.put(key, child.get(key));
      }
    }
    return targ;
  }
Beispiel #6
0
 /**
  * Checks if a <CODE>Dictionary</CODE> is of the type OUTLINES.
  *
  * @return <CODE>true</CODE> if it is, otherwise <CODE>false</CODE>.
  */
 public boolean isOutlineTree() {
   return OUTLINES.equals(dictionaryType);
 }
Beispiel #7
0
 /**
  * Checks if a <CODE>Dictionary</CODE> is of the type CATALOG.
  *
  * @return <CODE>true</CODE> if it is, otherwise <CODE>false</CODE>.
  */
 public boolean isCatalog() {
   return CATALOG.equals(dictionaryType);
 }
Beispiel #8
0
 /**
  * Checks if a <CODE>Dictionary</CODE> is of the type PAGES.
  *
  * @return <CODE>true</CODE> if it is, otherwise <CODE>false</CODE>.
  */
 public boolean isPages() {
   return PAGES.equals(dictionaryType);
 }
Beispiel #9
0
 /**
  * Checks if a <CODE>Dictionary</CODE> is of the type FONT.
  *
  * @return <CODE>true</CODE> if it is, otherwise <CODE>false</CODE>.
  */
 public boolean isFont() {
   return FONT.equals(dictionaryType);
 }