Don,
DonCapullo wrote:
>
> Hi Michael!
>
> We also need a quick fix to the problem - as we do not need any
> functionality but Signature verification, we do not change the PDf and
> hence will not have problems with PdfStamper and PdfCopy* classes. Would
> it be possible to send me the codding of your hepler method?
>
> kr Don
>
It would be possible... actually you quoted the code which was appended to
the message you originally replied to:
mkl wrote:
>
> /* $Id:$
> */
> package com.lowagie.text.pdf;
>
> import java.util.ArrayList;
> import java.util.HashMap;
> import java.util.Iterator;
> import java.util.Map;
>
> import com.lowagie.text.pdf.AcroFields.Item;
>
> public class AcroFieldsHelper
> {
> public static void fill(AcroFields acroFields) {
> acroFields.fields = new HashMap();
> PdfDictionary top =
> (PdfDictionary)PdfReader.getPdfObjectRelease(acroFields.reader.getCatalog().get(PdfName.ACROFORM));
> if (top == null)
> return;
> PdfArray arrfds =
> (PdfArray)PdfReader.getPdfObjectRelease(top.get(PdfName.FIELDS));
> if (arrfds == null || arrfds.size() == 0)
> return;
> Map fields = collectFields(arrfds, null);
> System.out.println("Acrofields found: " + fields);
> arrfds = null;
> for (int k = 1; k <= acroFields.reader.getNumberOfPages(); ++k) {
> PdfDictionary page = acroFields.reader.getPageNRelease(k);
> PdfArray annots =
> (PdfArray)PdfReader.getPdfObjectRelease(page.get(PdfName.ANNOTS), page);
> if (annots == null)
> continue;
> ArrayList arr = annots.getArrayList();
> for (int j = 0; j < arr.size(); ++j) {
> System.out.println("\nAnnotation " + arr.get(j));
> PdfObject annoto =
> PdfReader.getPdfObject((PdfObject)arr.get(j), annots);
> if (!(annoto instanceof PdfDictionary)) {
>
> PdfReader.releaseLastXrefPartial((PdfObject)arr.get(j));
> continue;
> }
> PdfDictionary annot = (PdfDictionary)annoto;
> if (!PdfName.WIDGET.equals(annot.get(PdfName.SUBTYPE))) {
>
> PdfReader.releaseLastXrefPartial((PdfObject)arr.get(j));
> continue;
> }
> PdfDictionary widget = annot;
> PdfDictionary dic = new PdfDictionary();
> dic.putAll(annot);
> String name = "";
> PdfDictionary value = null;
> PdfObject lastV = null;
> while (annot != null) {
> dic.mergeDifferent(annot);
> PdfString t =
> (PdfString)PdfReader.getPdfObject(annot.get(PdfName.T));
> if (t != null)
> name = t.toUnicodeString() + "." + name;
> if (lastV == null && annot.get(PdfName.V) != null)
> lastV =
> PdfReader.getPdfObjectRelease(annot.get(PdfName.V));
> if (value == null && t != null) {
> value = annot;
> if (annot.get(PdfName.V) == null && lastV !=
> null)
> value.put(PdfName.V, lastV);
> }
> PdfObject parent = annot.get(PdfName.PARENT);
> if (parent instanceof PdfIndirectReference)
> {
> System.out.println(" has parent " + parent);
> Integer number = new
> Integer(((PdfIndirectReference)parent).getNumber());
> fields.remove(number);
> }
> annot = (PdfDictionary)PdfReader.getPdfObject(parent,
> annot);
> }
> if (name.length() > 0)
> name = name.substring(0, name.length() - 1);
> Item item = (Item)acroFields.fields.get(name);
> if (item == null) {
> item = new Item();
> acroFields.fields.put(name, item);
> }
> if (value == null)
> item.values.add(widget);
> else
> item.values.add(value);
> item.widgets.add(widget);
> item.widget_refs.add(arr.get(j)); // must be a reference
> if (top != null)
> dic.mergeDifferent(top);
> item.merged.add(dic);
> item.page.add(new Integer(k));
> item.tabOrder.add(new Integer(j));
> }
> }
> System.out.println("Acrofields unaccounted for: " + fields);
> for(Iterator itUnbound = fields.entrySet().iterator();
> itUnbound.hasNext(); )
> {
> Map.Entry unboundEntry = (Map.Entry)itUnbound.next();
> System.out.println("\nUnbound " + unboundEntry.getValue());
> PdfDictionary field = (PdfDictionary)
> PdfReader.getPdfObject((PdfObject) unboundEntry.getValue());
> PdfDictionary dic = new PdfDictionary();
> dic.putAll(field);
> String name = "";
> PdfDictionary value = null;
> PdfObject lastV = null;
> while (field != null) {
> dic.mergeDifferent(field);
> PdfString t =
> (PdfString)PdfReader.getPdfObject(field.get(PdfName.T));
> if (t != null)
> name = t.toUnicodeString() + "." + name;
> if (lastV == null && field.get(PdfName.V) != null)
> lastV =
> PdfReader.getPdfObjectRelease(field.get(PdfName.V));
> if (value == null && t != null) {
> value = field;
> if (field.get(PdfName.V) == null && lastV != null)
> value.put(PdfName.V, lastV);
> }
> PdfObject parent = field.get(PdfName.PARENT);
> if (parent instanceof PdfIndirectReference)
> {
> System.out.println(" has parent " + parent);
> Integer number = new
> Integer(((PdfIndirectReference)parent).getNumber());
> fields.remove(number);
> }
> field = (PdfDictionary)PdfReader.getPdfObject(parent,
> field);
> }
> if (name.length() > 0)
> name = name.substring(0, name.length() - 1);
> Item item = (Item)acroFields.fields.get(name);
> if (item == null) {
> item = new Item();
> acroFields.fields.put(name, item);
> }
> if (value == null)
> item.values.add(field);
> else
> item.values.add(value);
> item.widgets.add(field);
> item.widget_refs.add(unboundEntry.getValue()); // must be a
> reference
> if (top != null)
> dic.mergeDifferent(top);
> item.merged.add(dic);
> item.page.add(new Integer(-1));
> item.tabOrder.add(new Integer(-1));
> }
> }
>
>
>
> static Map collectFields(PdfArray pdfArray, Map fields)
> {
> if (fields == null)
> fields = new HashMap();
>
> for (int j = 0; j < pdfArray.size(); ++j) {
> PdfIndirectReference fieldReference =
> pdfArray.getAsIndirectObject(j);
> Integer number = new Integer(fieldReference.getNumber());
> if (!fields.containsKey(number))
> {
> fields.put(number, fieldReference);
> PdfDictionary field = (PdfDictionary)
> PdfReader.getPdfObjectRelease(fieldReference);
> PdfArray contained =
> (PdfArray)PdfReader.getPdfObjectRelease(field.get(PdfName.FIELDS));
> if (contained != null)
> fields = collectFields(contained, fields);
> }
> }
>
> return fields;
> }
> }
>
Regards, Michael.
--
View this message in context:
http://www.nabble.com/Re%3A-Signature-not-found-%3A-Bug-or-feature---tp20382425p23643176.html
Sent from the iText - General mailing list archive at Nabble.com.
------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables
unlimited royalty-free distribution of the report engine
for externally facing server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://www.1t3xt.com/docs/book.php
Check the site with examples before you ask questions:
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/