/** * This method checks if the NeedAppearances entry is present. If it is, the value must be false. * * If the entry is invalid, the ERROR_SYNTAX_DICT_INVALID (1.2.3) error is return. * * @param ctx the preflight context. * @param acroForm the AcroForm. */ protected void checkNeedAppearences(PreflightContext ctx, PDAcroForm acroForm) { if (acroForm.getCOSObject().getBoolean(ACROFORM_DICTIONARY_KEY_NEED_APPEARANCES, false)) { addValidationError(ctx, new ValidationError(ERROR_SYNTAX_DICT_INVALID, "NeedAppearance is present with the value \"true\"")); } }
@Override public void createAcroFormDictionary(PDAcroForm acroForm, PDSignatureField signatureField) throws IOException { @SuppressWarnings("unchecked") List<PDField> acroFormFields = acroForm.getFields(); COSDictionary acroFormDict = acroForm.getCOSObject(); acroForm.setSignaturesExist(true); acroForm.setAppendOnly(true); acroFormDict.setDirect(true); acroFormFields.add(signatureField); // WTF sylfaen? acroForm.setDefaultAppearance("/sylfaen 0 Tf 0 g"); pdfStructure.setAcroFormFields(acroFormFields); pdfStructure.setAcroFormDictionary(acroFormDict); LOG.info("AcroForm dictionary has been created"); }
COSBase base = destAcroForm.getCOSObject().getItem(COSName.FIELDS); if (base instanceof COSArray) destAcroForm.getCOSObject().setItem(COSName.FIELDS,destFields);
/** * Returns the given attribute, inheriting from parent nodes if necessary. * * @param key the key to look up * @return COS value for the given key */ protected COSBase getInheritableAttribute(COSName key) { if (dictionary.containsKey(key)) { return dictionary.getDictionaryObject(key); } else if (parent != null) { return parent.getInheritableAttribute(key); } else { return acroForm.getCOSObject().getDictionaryObject(key); } }
cloner.cloneForNewDocument(srcAcroForm.getCOSObject()));
acroForm.getCOSObject().setNeedToBeUpdated(true); if (!(acroForm.getCOSObject().getDictionaryObject(COSName.FIELDS) instanceof COSArray)) acroForm.getCOSObject().setItem(COSName.FIELDS, new COSArray()); COSArray fieldArray = (COSArray) acroForm.getCOSObject().getDictionaryObject(COSName.FIELDS); fieldArray.setNeedToBeUpdated(true); signatureField = findSignatureField(acroForm.getFieldIterator(), sigObject); acroForm.getCOSObject().setDirect(true); acroForm.setSignaturesExist(true); acroForm.setAppendOnly(true);
acroForm.getCOSObject().removeItem(COSName.NEED_APPEARANCES);
private void assignAcroFormDefaultResource(PDAcroForm acroForm, COSDictionary newDict) { // read and set/update AcroForm default resource dictionary /DR if available COSBase newBase = newDict.getDictionaryObject(COSName.DR); if (newBase instanceof COSDictionary) { COSDictionary newDR = (COSDictionary) newBase; PDResources defaultResources = acroForm.getDefaultResources(); if (defaultResources == null) { acroForm.getCOSObject().setItem(COSName.DR, newDR); newDR.setDirect(true); newDR.setNeedToBeUpdated(true); } else { COSDictionary oldDR = defaultResources.getCOSObject(); COSBase newXObjectBase = newDR.getItem(COSName.XOBJECT); COSBase oldXObjectBase = oldDR.getItem(COSName.XOBJECT); if (newXObjectBase instanceof COSDictionary && oldXObjectBase instanceof COSDictionary) { ((COSDictionary) oldXObjectBase).addAll((COSDictionary) newXObjectBase); oldDR.setNeedToBeUpdated(true); } } } }
acroForm.getCOSObject().removeItem(COSName.NEED_APPEARANCES);
private List<CosObject> getXFA() { org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm form = (org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm) this.simplePDObject; if (form.hasXFA()) { COSBase value = form.getCOSObject().getDictionaryObject(COSName.XFA); boolean isStream = value instanceof COSStream; if (isStream || value instanceof COSArray) { ArrayList<CosObject> list = new ArrayList<>(MAX_NUMBER_OF_ELEMENTS); if (isStream) { list.add(new PBCosStream((COSStream) value, this.document, this.flavour)); } else { list.add(new PBCosArray((COSArray) value, this.document, this.flavour)); } return Collections.unmodifiableList(list); } } return Collections.emptyList(); } }
acroForm.setSignaturesExist(true); acroForm.setAppendOnly(true); acroForm.getCOSObject().setDirect(true); acroFormFields.add(signatureField);
/** * This method checks if the NeedAppearances entry is present. If it is, the value must be false. * * If the entry is invalid, the ERROR_SYNTAX_DICT_INVALID (1.2.3) error is return. * * @param ctx the preflight context. * @param acroForm the AcroForm. */ protected void checkNeedAppearences(PreflightContext ctx, PDAcroForm acroForm) { if (acroForm.getCOSObject().getBoolean(ACROFORM_DICTIONARY_KEY_NEED_APPEARANCES, false)) { addValidationError(ctx, new ValidationError(ERROR_SYNTAX_DICT_INVALID, "NeedAppearance is present with the value \"true\"")); } }
/** * This method checks if the NeedAppearances entry is present. If it is, the value must be false. * * If the entry is invalid, the ERROR_SYNTAX_DICT_INVALID (1.2.3) error is return. * * @param ctx the preflight context. * @param acroForm the AcroForm. */ protected void checkNeedAppearences(PreflightContext ctx, PDAcroForm acroForm) { if (acroForm.getCOSObject().getBoolean(ACROFORM_DICTIONARY_KEY_NEED_APPEARANCES, false)) { addValidationError(ctx, new ValidationError(ERROR_SYNTAX_DICT_INVALID, "NeedAppearance is present with the value \"true\"")); } }
@Override public void createAcroFormDictionary(PDAcroForm acroForm, PDSignatureField signatureField) throws IOException { @SuppressWarnings("unchecked") List<PDField> acroFormFields = acroForm.getFields(); COSDictionary acroFormDict = acroForm.getCOSObject(); acroForm.setSignaturesExist(true); acroForm.setAppendOnly(true); acroFormDict.setDirect(true); acroFormFields.add(signatureField); acroForm.setDefaultAppearance("/sylfaen 0 Tf 0 g"); pdfStructure.setAcroFormFields(acroFormFields); pdfStructure.setAcroFormDictionary(acroFormDict); LOG.info("AcroForm dictionary has been created"); }
@Override public void createAcroFormDictionary(PDAcroForm acroForm, PDSignatureField signatureField) throws IOException { @SuppressWarnings("unchecked") List<PDField> acroFormFields = acroForm.getFields(); COSDictionary acroFormDict = acroForm.getCOSObject(); acroForm.setSignaturesExist(true); acroForm.setAppendOnly(true); acroFormDict.setDirect(true); acroFormFields.add(signatureField); acroForm.setDefaultAppearance("/sylfaen 0 Tf 0 g"); pdfStructure.setAcroFormFields(acroFormFields); pdfStructure.setAcroFormDictionary(acroFormDict); LOG.info("AcroForm dictionary has been created"); }
/** * Returns the given attribute, inheriting from parent nodes if necessary. * * @param key the key to look up * @return COS value for the given key */ protected COSBase getInheritableAttribute(COSName key) { if (dictionary.containsKey(key)) { return dictionary.getDictionaryObject(key); } else if (parent != null) { return parent.getInheritableAttribute(key); } else { return acroForm.getCOSObject().getDictionaryObject(key); } }
COSArray destFields = (COSArray) destAcroForm.getCOSObject().getItem(COSName.FIELDS); for (PDField srcField : srcAcroForm.getFieldTree()) destAcroForm.getCOSObject().setItem(COSName.FIELDS,destFields);
/** * Returns the given attribute, inheriting from parent nodes if necessary. * * @param key the key to look up * @return COS value for the given key */ protected COSBase getInheritableAttribute(COSName key) { if (dictionary.containsKey(key)) { return dictionary.getDictionaryObject(key); } else if (parent != null) { return parent.getInheritableAttribute(key); } else { return acroForm.getCOSObject().getDictionaryObject(key); } }
private void assignAcroFormDefaultResource(PDAcroForm acroForm, COSDictionary newDict) { // read and set/update AcroForm default resource dictionary /DR if available COSBase newBase = newDict.getDictionaryObject(COSName.DR); if (newBase instanceof COSDictionary) { COSDictionary newDR = (COSDictionary) newBase; PDResources defaultResources = acroForm.getDefaultResources(); if (defaultResources == null) { acroForm.getCOSObject().setItem(COSName.DR, newDR); newDR.setDirect(true); newDR.setNeedToBeUpdated(true); } else { COSDictionary oldDR = defaultResources.getCOSObject(); COSBase newXObjectBase = newDR.getItem(COSName.XOBJECT); COSBase oldXObjectBase = oldDR.getItem(COSName.XOBJECT); if (newXObjectBase instanceof COSDictionary && oldXObjectBase instanceof COSDictionary) { ((COSDictionary) oldXObjectBase).addAll((COSDictionary) newXObjectBase); oldDR.setNeedToBeUpdated(true); } } } }
private void assignAcroFormDefaultResource(PDAcroForm acroForm, COSDictionary newDict) { // read and set/update AcroForm default resource dictionary /DR if available COSBase newBase = newDict.getDictionaryObject(COSName.DR); if (newBase instanceof COSDictionary) { COSDictionary newDR = (COSDictionary) newBase; PDResources defaultResources = acroForm.getDefaultResources(); if (defaultResources == null) { acroForm.getCOSObject().setItem(COSName.DR, newDR); newDR.setDirect(true); newDR.setNeedToBeUpdated(true); } else { COSDictionary oldDR = defaultResources.getCOSObject(); COSBase newXObjectBase = newDR.getItem(COSName.XOBJECT); COSBase oldXObjectBase = oldDR.getItem(COSName.XOBJECT); if (newXObjectBase instanceof COSDictionary && oldXObjectBase instanceof COSDictionary) { ((COSDictionary) oldXObjectBase).addAll((COSDictionary) newXObjectBase); oldDR.setNeedToBeUpdated(true); } } } }