Ejemplo n.º 1
0
 /**
  * This method scans the document for all WidgetAnnotation objects.
  *
  * <p>This is done because some writer do not create a correct list of all PDAcroFormField objects
  * in the AcroForm. In the case that the list of children is empty, we go and search ourselves for
  * candidates...
  *
  * @param doc The document to reconstruct.
  */
 protected COSArray reconstruct(PDDocument doc) {
   COSArray result = COSArray.create();
   if (doc == null) {
     return result;
   }
   PDPageTree pageTree = doc.getPageTree();
   if (pageTree == null) {
     return result;
   }
   boolean signatureExists = false;
   for (PDPage page = pageTree.getFirstPage(); page != null; page = page.getNextPage()) {
     List annotations = page.getAnnotations();
     if (annotations == null) {
       continue;
     }
     for (Iterator it = annotations.iterator(); it.hasNext(); ) {
       PDAnnotation annot = (PDAnnotation) it.next();
       if (annot.isWidgetAnnotation()) {
         COSDictionary cosAnnot = annot.cosGetDict();
         result.basicAddSilent(cosAnnot);
         cosAnnot.basicRemoveSilent(PDAcroFormField.DK_Parent);
         signatureExists |= cosAnnot.get(PDAcroFormField.DK_FT).equals(PDAcroFormField.CN_FT_Sig);
       }
     }
   }
   if (signatureExists) {
     int flags = getFieldInt(PDAcroForm.DK_SigFlags, 0);
     flags |= AcroFormSigFlags.Bit_AppendOnly | AcroFormSigFlags.Bit_SignatureExists;
     cosGetDict().basicPutSilent(PDAcroForm.DK_SigFlags, COSInteger.create(flags));
   }
   return result;
 }
 /**
  * The destination page. ATTENTION: it is common have dangling destinations to invalid (null)
  * pages around!
  *
  * @return The destination page. Be sure to handle null return values.
  */
 public PDPage getPage(PDDocument doc) {
   COSArray definition = cosGetArray();
   COSObject page = definition.get(0);
   if (page.asNumber() != null) {
     int pageIndex = page.asNumber().intValue();
     return doc.getPageTree().getPageAt(pageIndex);
   }
   if (page.asDictionary() != null) {
     return (PDPage) PDPageNode.META.createFromCos(page.asDictionary());
   }
   return null;
 }