/** * Gets a new signature fied name that doesn't clash with any existing name. * @return a new signature fied name */ public String getNewSigName() { final AcroFields af = this.writer.getAcroFields(); String name = "Signature"; //$NON-NLS-1$ int step = 0; boolean found = false; while (!found) { ++step; String n1 = name + step; if (af.getFieldItem(n1) != null) { continue; } n1 += "."; //$NON-NLS-1$ found = true; for (final Iterator it = af.getFields().keySet().iterator(); it.hasNext();) { final String fn = (String)it.next(); if (fn.startsWith(n1)) { found = false; break; } } } name += step; return name; }
/** * Gets a new signature fied name that doesn't clash with any existing name. * @return a new signature fied name */ public String getNewSigName() { AcroFields af = writer.getAcroFields(); String name = "Signature"; int step = 0; boolean found = false; while (!found) { ++step; String n1 = name + step; if (af.getFieldItem(n1) != null) continue; n1 += "."; found = true; for (Iterator it = af.getFields().keySet().iterator(); it.hasNext();) { String fn = (String)it.next(); if (fn.startsWith(n1)) { found = false; break; } } } name += step; return name; }
/** * Gets a new signature fied name that doesn't clash with any existing name. * * @return a new signature fied name */ public final String getNewSigName() { AcroFields af = writer.getAcroFields(); String name = "Signature"; int step = 0; boolean found = false; while (!found) { ++step; String n1 = name + step; if (af.getFieldItem(n1) != null) continue; n1 += "."; found = true; for (Iterator it = af.getFields().keySet().iterator(); it.hasNext();) { String fn = (String) it.next(); if (fn.startsWith(n1)) { found = false; break; } } } name += step; return name; }
/** * Sets the signature to be visible. It creates a new visible signature field. * @param pageRect the position and dimension of the field in the page * @param page the page to place the field. The fist page is 1 * @param fieldName the field name or <CODE>null</CODE> to generate automatically a new field name */ public void setVisibleSignature(final Rectangle pageRect, final int page, final String fieldName) { if (fieldName != null) { if (fieldName.indexOf('.') >= 0) { throw new IllegalArgumentException("Field names cannot contain a dot."); //$NON-NLS-1$ } final AcroFields af = this.writer.getAcroFields(); final AcroFields.Item item = af.getFieldItem(fieldName); if (item != null) { throw new IllegalArgumentException("The field " + fieldName + " already exists."); //$NON-NLS-1$ //$NON-NLS-2$ } this.fieldName = fieldName; } if (page < 1 || page > this.writer.reader.getNumberOfPages()) { throw new IllegalArgumentException("Invalid page number: " + page); //$NON-NLS-1$ } this.pageRect = new Rectangle(pageRect); this.pageRect.normalize(); this.rect = new Rectangle(this.pageRect.getWidth(), this.pageRect.getHeight()); this.page = page; this.newField = true; }
/** * Sets the signature to be visible. It creates a new visible signature field. * @param pageRect the position and dimension of the field in the page * @param page the page to place the field. The fist page is 1 * @param fieldName the field name or <CODE>null</CODE> to generate automatically a new field name */ public void setVisibleSignature(Rectangle pageRect, int page, String fieldName) { if (fieldName != null) { if (fieldName.indexOf('.') >= 0) throw new IllegalArgumentException(MessageLocalization.getComposedMessage("field.names.cannot.contain.a.dot")); AcroFields af = writer.getAcroFields(); AcroFields.Item item = af.getFieldItem(fieldName); if (item != null) throw new IllegalArgumentException(MessageLocalization.getComposedMessage("the.field.1.already.exists", fieldName)); this.fieldName = fieldName; } if (page < 1 || page > writer.reader.getNumberOfPages()) throw new IllegalArgumentException(MessageLocalization.getComposedMessage("invalid.page.number.1", page)); this.pageRect = new Rectangle(pageRect); this.pageRect.normalize(); rect = new Rectangle(this.pageRect.getWidth(), this.pageRect.getHeight()); this.page = page; newField = true; }
.getComposedMessage("field.names.cannot.contain.a.dot")); AcroFields af = writer.getAcroFields(); AcroFields.Item item = af.getFieldItem(fieldName); if (item != null) throw new IllegalArgumentException(
/** * @since 2.1.5; before 2.1.5 the method was private */ protected void updateCalculationOrder(PdfReader reader) { PdfDictionary catalog = reader.getCatalog(); PdfDictionary acro = catalog.getAsDict(PdfName.ACROFORM); if (acro == null) return; PdfArray co = acro.getAsArray(PdfName.CO); if (co == null || co.size() == 0) return; AcroFields af = reader.getAcroFields(); for (int k = 0; k < co.size(); ++k) { PdfObject obj = co.getPdfObject(k); if (obj == null || !obj.isIndirect()) continue; String name = getCOName(reader, (PRIndirectReference)obj); if (af.getFieldItem(name) == null) continue; name = "." + name; if (calculationOrder.contains(name)) continue; calculationOrder.add(name); } }
/** * @since 2.1.5; before 2.1.5 the method was private */ protected void updateCalculationOrder(PdfReader reader) { PdfDictionary catalog = reader.getCatalog(); PdfDictionary acro = catalog.getAsDict(PdfName.ACROFORM); if (acro == null) return; PdfArray co = acro.getAsArray(PdfName.CO); if (co == null || co.size() == 0) return; AcroFields af = reader.getAcroFields(); for (int k = 0; k < co.size(); ++k) { PdfObject obj = co.getPdfObject(k); if (obj == null || !obj.isIndirect()) continue; String name = getCOName(reader, (PRIndirectReference)obj); if (af.getFieldItem(name) == null) continue; name = "." + name; if (calculationOrder.contains(name)) continue; calculationOrder.add(name); } }
/** * @since 2.1.5; before 2.1.5 the method was private */ protected void updateCalculationOrder(PdfReader reader) { PdfDictionary catalog = reader.getCatalog(); PdfDictionary acro = catalog.getAsDict(PdfName.ACROFORM); if (acro == null) return; PdfArray co = acro.getAsArray(PdfName.CO); if (co == null || co.size() == 0) return; AcroFields af = reader.getAcroFields(); for (int k = 0; k < co.size(); ++k) { PdfObject obj = co.getPdfObject(k); if (obj == null || !obj.isIndirect()) continue; String name = getCOName(reader, (PRIndirectReference)obj); if (af.getFieldItem(name) == null) continue; name = "." + name; if (calculationOrder.contains(name)) continue; calculationOrder.add(name); } }
Item item = getFieldItem(name); if (item == null) return false;
return false; Item item = getFieldItem(field); if (order >= item.size()) { return false;
if (getFieldType(field) != FIELD_TYPE_PUSHBUTTON) return false; Item item = getFieldItem(field); if (order >= item.size()) return false;
if (getFieldType(field) != FIELD_TYPE_PUSHBUTTON) return false; Item item = getFieldItem(field); if (order >= item.size()) return false;
private String[] getListOption(String fieldName, int idx) { Item fd = getFieldItem(fieldName); if (fd == null) { return null; } PdfArray ar = fd.getMerged(0).getAsArray(PdfName.OPT); if (ar == null) { return null; } String[] ret = new String[ar.size()]; for (int k = 0; k < ar.size(); ++k) { PdfObject obj = ar.getDirectObject(k); try { if (obj.isArray()) { obj = ((PdfArray) obj).getDirectObject(idx); } if (obj.isString()) { ret[k] = ((PdfString) obj).toUnicodeString(); } else { ret[k] = obj.toString(); } } catch (Exception e) { ret[k] = ""; } } return ret; }
private String[] getListOption(String fieldName, int idx) { Item fd = getFieldItem(fieldName); if (fd == null) return null; PdfArray ar = fd.getMerged(0).getAsArray(PdfName.OPT); if (ar == null) return null; String[] ret = new String[ar.size()]; for (int k = 0; k < ar.size(); ++k) { PdfObject obj = ar.getDirectObject( k ); try { if (obj.isArray()) { obj = ((PdfArray)obj).getDirectObject(idx); } if (obj.isString()) ret[k] = ((PdfString)obj).toUnicodeString(); else ret[k] = obj.toString(); } catch (Exception e) { ret[k] = ""; } } return ret; }
private String[] getListOption(String fieldName, int idx) { Item fd = getFieldItem(fieldName); if (fd == null) return null; PdfArray ar = fd.getMerged(0).getAsArray(PdfName.OPT); if (ar == null) return null; String[] ret = new String[ar.size()]; for (int k = 0; k < ar.size(); ++k) { PdfObject obj = ar.getDirectObject( k ); try { if (obj.isArray()) { obj = ((PdfArray)obj).getDirectObject(idx); } if (obj.isString()) ret[k] = ((PdfString)obj).toUnicodeString(); else ret[k] = obj.toString(); } catch (Exception e) { ret[k] = ""; } } return ret; }
Item item = getFieldItem(name); if (item == null) { return false;
Item item = getFieldItem(name); if (item == null) return false;
final AcroFields.Item item = af.getFieldItem(fieldName); if (item == null) { throw new IllegalArgumentException("The field " + fieldName + " does not exist."); //$NON-NLS-1$ //$NON-NLS-2$
AcroFields.Item item = af.getFieldItem(fieldName); if (item == null) throw new IllegalArgumentException(MessageLocalization.getComposedMessage("the.field.1.does.not.exist", fieldName));