/** * This method merges different fields from two dictionaries into the current one * @param other a dictionary whose fields should be merged into the current dictionary. */ public void mergeDifferent(PdfDictionary other){ for (PdfName key : other.keySet()){ if(!containsKey(key)) put(key, other.get(key)); } }
/** * Gets the {@link PdfArray} of numbers specifying how to map vertex coordinates and colour components * into the appropriate ranges of values. The ranges shall be specified as follows: * [x_min x_max y_min y_max c1_min c1_max … cn_min cn_max]. * Only one pair of color values shall be specified if a Function entry is present. * * @return the {@link PdfArray} Decode object. */ public PdfArray getDecode() { return getPdfObject().getAsArray(PdfName.Decode); }
private void updateValueInMarkInfoDict(PdfName key, PdfObject value) { PdfDictionary markInfo = catalog.getPdfObject().getAsDictionary(PdfName.MarkInfo); if (markInfo == null) { markInfo = new PdfDictionary(); catalog.getPdfObject().put(PdfName.MarkInfo, markInfo); } markInfo.put(key, value); }
public TagReference addProperty(PdfName name, PdfObject value) { if (properties == null) { properties = new PdfDictionary(); } properties.put(name, value); return this; }
private static String getOrdering(PdfDictionary cidFont) { PdfDictionary cidinfo = cidFont.getAsDictionary(PdfName.CIDSystemInfo); if (cidinfo == null) return null; return cidinfo.containsKey(PdfName.Ordering) ? cidinfo.get(PdfName.Ordering).toString() : null; }
@Override protected void checkPageObject(PdfDictionary pageDict, PdfDictionary pageResources) { PdfDictionary actions = pageDict.getAsDictionary(PdfName.AA); if (actions != null) { for (PdfName key : actions.keySet()) { PdfDictionary action = actions.getAsDictionary(key); checkAction(action); } } if (pageDict.containsKey(PdfName.Group) && PdfName.Transparency.equals(pageDict.getAsDictionary(PdfName.Group).getAsName(PdfName.S))) { throw new PdfAConformanceException(PdfAConformanceException.A_GROUP_OBJECT_WITH_AN_S_KEY_WITH_A_VALUE_OF_TRANSPARENCY_SHALL_NOT_BE_INCLUDED_IN_A_PAGE_XOBJECT); } }
private void ensureTreeRootAddedToNames(PdfObject treeRoot, PdfName treeType) { PdfDictionary names = catalog.getPdfObject().getAsDictionary(PdfName.Names); if (names == null) { names = new PdfDictionary(); catalog.put(PdfName.Names, names); names.makeIndirect(this); } names.put(treeType, treeRoot); }
/** * Return the XFA Object, could be an array, could be a Stream. * Returns null if no XFA Object is present. * * @param pdfDocument a PdfDocument instance * @return the XFA object */ private static PdfObject getXfaObject(PdfDocument pdfDocument) { PdfDictionary af = pdfDocument.getCatalog().getPdfObject().getAsDictionary(PdfName.AcroForm); return af == null ? null : af.get(PdfName.XFA); }
/** * The annotation’s appearance state, which selects the applicable appearance stream * from an appearance subdictionary if there is such. See {@link PdfAnnotation#getAppearanceObject(PdfName)} * for more info. * * @return a {@link PdfName} which defines selected appearance state. */ public PdfName getAppearanceState() { return getPdfObject().getAsName(PdfName.AS); }
public PdfStructElem(PdfDocument document, PdfName role) { this((PdfDictionary) new PdfDictionary().makeIndirect(document)); getPdfObject().put(PdfName.Type, PdfName.StructElem); getPdfObject().put(PdfName.S, role); }
/** * Indicates that the group contains a pagination artifact. * @param pe one of the following names: "HF" (Header Footer), * "FG" (Foreground), "BG" (Background), or "L" (Logo). */ public void setPageElement(String pe) { PdfDictionary usage = getUsage(); PdfDictionary dic = new PdfDictionary(); dic.put(PdfName.Subtype, new PdfName(pe)); usage.put(PdfName.PageElement, dic); usage.setModified(); }
/** * Returns the value associated to this key. * * @param key the key of which the associated value needs to be returned * @return the value associated with this key */ public PdfObject get(PdfName key) { return get(key, true); }
/** * @deprecated Will always return null. The return will be changed to PdfName in 7.2. * Use {@code getPdfObject().getAsName(PdfName.View)}, * or one of {@link #isViewDetails()}, {@link #isViewTile()}, {@link #isViewHidden()}. */ @Deprecated public PdfNumber getView() { return getPdfObject().getAsNumber(PdfName.View); }
private void updateProducerInInfoDictionary() { String producer = null; if (reader == null) { producer = versionInfo.getVersion(); } else { if (info.getPdfObject().containsKey(PdfName.Producer)) { producer = info.getPdfObject().getAsString(PdfName.Producer).toUnicodeString(); } producer = addModifiedPostfix(producer); } info.getPdfObject().put(PdfName.Producer, new PdfString(producer)); }
private PdfName getTypeFromParent(PdfDictionary field) { PdfDictionary parent = field.getAsDictionary(PdfName.Parent); PdfName formType = field.getAsName(PdfName.FT); if (parent != null) { formType = parent.getAsName(PdfName.FT); if (formType == null) { formType = getTypeFromParent(parent); } } return formType; }
/** * Method to to distinguish struct elements from other elements of the logical tree (like mcr or struct tree root). */ public static boolean isStructElem(PdfDictionary dictionary) { return (PdfName.StructElem.equals(dictionary.getAsName(PdfName.Type)) || dictionary.containsKey(PdfName.S)); // required key of the struct elem }
/** * Gets the names of all resources of specified type. * * @param resType the resource type. Should be {@link PdfName#ColorSpace}, {@link PdfName#ExtGState}, * {@link PdfName#Pattern}, {@link PdfName#Shading}, {@link PdfName#XObject}, {@link PdfName#Font}. * @return set of resources name of corresponding type. May be empty. * Will be empty in case of incorrect resource type. */ public Set<PdfName> getResourceNames(PdfName resType) { PdfDictionary resourceCategory = getPdfObject().getAsDictionary(resType); return resourceCategory == null ? new TreeSet<PdfName>() : resourceCategory.keySet(); // TODO: TreeSet or HashSet enough? }
private static void appendSyntaxString(PdfDictionary dictionary) { stringBuilder.append("<< "); for (PdfName key : dictionary.keySet()) { safeAppendSyntaxString(key); stringBuilder.append(" "); safeAppendSyntaxString(dictionary.get(key, false)); stringBuilder.append(" "); } stringBuilder.append(">>"); }
private boolean ensureElementPageEqualsKidPage(PdfStructElem elem, PdfDictionary kidPage) { PdfObject pageObject = elem.getPdfObject().get(PdfName.Pg); if (pageObject == null) { pageObject = kidPage; elem.getPdfObject().put(PdfName.Pg, kidPage); elem.setModified(); } return kidPage.equals(pageObject); }