/** * 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; }
public void setPage(PDPage page) { COSArray definition = cosGetArray(); if (definition.size() == 0) { definition.add(page.cosGetObject()); } else { definition.set(0, page.cosGetObject()); } }