List of usage examples for org.apache.pdfbox.cos COSDictionary keySet
public Set<COSName> keySet()
From source file:net.padaf.preflight.helpers.TrailerValidationHelper.java
License:Apache License
/** * Check if mandatory keys of linearized dictionary are present. * /*from w ww . j av a 2s . com*/ * @param lErrors */ protected void checkLinearizedDictionnary(COSDictionary linearizedDict, List<ValidationError> lErrors) { // ---- check if all keys are authorized in a linearized dictionary // ---- Linearized dictionary must contain the lhoent keys boolean l = false; boolean h = false; boolean o = false; boolean e = false; boolean n = false; boolean t = false; for (Object key : linearizedDict.keySet()) { if (!(key instanceof COSName)) { lErrors.add(new ValidationResult.ValidationError( ValidationConstants.ERROR_SYNTAX_DICTIONARY_KEY_INVALID, "Invalid key in The Linearized dictionary")); return; } String cosName = ((COSName) key).getName(); if (cosName.equals(DICTIONARY_KEY_LINEARIZED_L)) { l = true; } if (cosName.equals(DICTIONARY_KEY_LINEARIZED_H)) { h = true; } if (cosName.equals(DICTIONARY_KEY_LINEARIZED_O)) { o = true; } if (cosName.equals(DICTIONARY_KEY_LINEARIZED_E)) { e = true; } if (cosName.equals(DICTIONARY_KEY_LINEARIZED_N)) { n = true; } if (cosName.equals(DICTIONARY_KEY_LINEARIZED_T)) { t = true; } } if (!(l && h && o && e && t && n)) { lErrors.add(new ValidationResult.ValidationError(ValidationConstants.ERROR_SYNTAX_DICT_INVALID, "Invalid key in The Linearized dictionary")); } return; }
From source file:org.apache.fop.render.pdf.pdfbox.PDFBoxAdapter.java
License:Apache License
private void transferDict(COSDictionary orgDict, PDFStream targetDict, Set filter, boolean inclusive) throws IOException { Set<COSName> keys = orgDict.keySet(); for (COSName key : keys) { if (inclusive && !filter.contains(key.getName())) { continue; } else if (!inclusive && filter.contains(key.getName())) { continue; }//from w w w . j av a2s.co m targetDict.put(key.getName(), cloneForNewDocument(orgDict.getItem(key))); } }
From source file:org.apache.fop.render.pdf.pdfbox.PDFBoxAdapter.java
License:Apache License
private void mergeXObj(COSDictionary sourcePageResources, FontInfo fontinfo, UniqueName uniqueName) throws IOException { COSDictionary xobj = (COSDictionary) sourcePageResources.getDictionaryObject(COSName.XOBJECT); if (xobj != null && pdfDoc.isMergeFontsEnabled()) { for (Map.Entry<COSName, COSBase> i : xobj.entrySet()) { COSObject v = (COSObject) i.getValue(); COSStream stream = (COSStream) v.getObject(); COSDictionary res = (COSDictionary) stream.getDictionaryObject(COSName.RESOURCES); if (res != null) { COSDictionary src = (COSDictionary) res.getDictionaryObject(COSName.FONT); if (src != null) { COSDictionary target = (COSDictionary) sourcePageResources .getDictionaryObject(COSName.FONT); if (target == null) { sourcePageResources.setItem(COSName.FONT, src); } else { for (Map.Entry<COSName, COSBase> entry : src.entrySet()) { if (!target.keySet().contains(entry.getKey())) { target.setItem(uniqueName.getName(entry.getKey()), entry.getValue()); }/*from ww w . jav a2 s . com*/ } } PDFWriter writer = new MergeFontsPDFWriter(src, fontinfo, uniqueName, parentFonts, 0); String c = writer.writeText(new PDStream(stream)); if (c != null) { stream.removeItem(COSName.FILTER); newXObj.put(i.getKey(), c); for (Object e : src.keySet().toArray()) { COSName name = (COSName) e; src.setItem(uniqueName.getName(name), src.getItem(name)); src.removeItem(name); } } } } } } }
From source file:org.apache.fop.render.pdf.pdfbox.PDFBoxAdapter.java
License:Apache License
private void updateXObj(COSDictionary sourcePageResources, PDFDictionary pageResources) throws IOException { COSDictionary xobj = (COSDictionary) sourcePageResources.getDictionaryObject(COSName.XOBJECT); if (xobj != null && pdfDoc.isMergeFontsEnabled()) { PDFDictionary target = (PDFDictionary) pageResources.get("XObject"); for (COSName entry : xobj.keySet()) { if (newXObj.containsKey(entry)) { PDFStream s = (PDFStream) target.get(entry.getName()); s.setData(newXObj.get(entry).getBytes("ISO-8859-1")); PDFDictionary xobjr = (PDFDictionary) s.get("Resources"); xobjr.put("Font", pageResources.get("Font")); }/*from www.ja v a2 s .c o m*/ } } }
From source file:org.apache.fop.render.pdf.pdfbox.StructureTreeMerger.java
License:Apache License
public void createDirectDescendants(COSBase base, PDFStructElem parent) throws IOException { if (base instanceof COSDictionary) { COSDictionary baseDict = (COSDictionary) base; if (baseDict.keySet().contains(COSName.K)) { createDirectDescendants(baseDict.getItem(COSName.K), parent); }/*from w w w . j a v a 2s .co m*/ } else if (base instanceof COSArray) { COSArray array = (COSArray) base; for (int i = 0; i < array.size(); i++) { createDirectDescendants(array.get(i), parent); } } else { assert base instanceof COSObject; COSObject obj = (COSObject) base; createAndRegisterStructElem(obj); PDFStructElem elem = structElemCache.get((int) obj.getObjectNumber()); copyElemEntries(obj, elem); parent.addKid(elem); elem.setParent(parent); COSBase objKid = obj.getItem(COSName.K); if (objKid != null) { createDirectDescendants(objKid, elem); } } }
From source file:org.apache.fop.render.pdf.pdfbox.StructureTreeMerger.java
License:Apache License
private void copyElemEntries(COSBase base, PDFStructElem elem) throws IOException { assert base instanceof COSObject; COSObject baseObj = (COSObject) base; COSDictionary baseDic = (COSDictionary) baseObj.getObject(); COSName[] names = { COSName.TYPE, COSName.S, COSName.PG, COSName.ALT, COSName.LANG, COSName.A, COSName.ACTUAL_TEXT, COSName.T, COSName.E, COSName.C }; for (COSName name : names) { if (baseDic.keySet().contains(name)) { if (name.equals(COSName.PG)) { elem.put(COSName.PG.getName(), targetPage.makeReference()); } else { elem.put(name.getName(), adapter.cloneForNewDocument(baseDic.getItem(name))); }/*from w w w.j av a 2s . co m*/ } } adapter.cacheClonedObject(base, elem); }
From source file:org.apache.fop.render.pdf.pdfbox.StructureTreeMerger.java
License:Apache License
private void createKidFromCOSDictionary(COSDictionary mcrDict, PDFStructElem parent, COSDictionary baseDict) throws IOException { Collection<COSName> exclude = Arrays.asList(COSName.PG); PDFReference referenceObj;/*from ww w .ja va 2s . com*/ if (isElementFromSourcePage(mcrDict, baseDict)) { PDFDictionary contentItem = (PDFDictionary) adapter.cloneForNewDocument(mcrDict, mcrDict, exclude); if (mcrDict.keySet().contains(COSName.TYPE)) { String type = ((COSName) mcrDict.getDictionaryObject(COSName.TYPE)).getName(); if (type.equals("OBJR")) { COSObject obj = (COSObject) mcrDict.getItem(COSName.OBJ); if (adapter.getCachedClone(obj) == null) { referenceObj = null; } else { referenceObj = ((PDFObject) adapter.getCachedClone(obj)).makeReference(); } contentItem.put(COSName.OBJ.getName(), referenceObj); updateStructParentAndAddToPageParentTree(referenceObj, parent); } else if (type.equals("MCR")) { updateMCIDEntry(contentItem); markedContentMap.put( (((PDFNumber) contentItem.get(COSName.MCID.getName())).getNumber()).intValue(), parent); } } if (mcrDict.keySet().contains(COSName.PG)) { contentItem.put(COSName.PG.getName(), targetPage.makeReference()); } else { parent.put(COSName.PG.getName(), targetPage.makeReference()); } parent.addKid(contentItem); } else { parent.addKid(null); } }
From source file:org.apache.fop.render.pdf.pdfbox.StructureTreeMerger.java
License:Apache License
private boolean isStructureTreeRoot(COSDictionary elem) { if (elem.keySet().contains(COSName.TYPE)) { COSName type = (COSName) elem.getDictionaryObject(COSName.TYPE); return type.equals(COSName.STRUCT_TREE_ROOT); }/*from w w w . j av a2 s . c o m*/ return false; }
From source file:org.apache.fop.render.pdf.pdfbox.TaggedPDFConductor.java
License:Apache License
private boolean isParentTreeIsPresent(COSDictionary strucRootDict) { return strucRootDict.keySet().contains(COSName.PARENT_TREE); }
From source file:org.apache.fop.render.pdf.pdfbox.UniqueName.java
License:Apache License
private List<COSName> getResourceNames(COSDictionary sourcePageResources) { List<COSName> resourceNames = new ArrayList<COSName>(); for (COSBase e : sourcePageResources.getValues()) { if (e instanceof COSObject) { e = ((COSObject) e).getObject(); }/*from w ww. ja v a2 s . c om*/ if (e instanceof COSDictionary) { COSDictionary d = (COSDictionary) e; resourceNames.addAll(d.keySet()); } } return resourceNames; }