List of usage examples for org.apache.pdfbox.cos COSDictionary entrySet
public Set<Map.Entry<COSName, COSBase>> entrySet()
From source file:org.lockss.pdf.pdfbox.PdfBoxTokens.java
License:Open Source License
/** * <p>/*from w w w . j a v a 2s .co m*/ * Converts from a {@link COSDictionary} to a map from strings * (PDF names) to PDF tokens. * </p> * @param cosDictionary A {@link COSDictionary} instance. * @return A map from string to PDF tokens. * @since 1.56 */ protected static Map<String, PdfToken> getDictionary(COSDictionary cosDictionary) { Map<String, PdfToken> ret = new LinkedHashMap<String, PdfToken>(); for (Map.Entry<COSName, COSBase> entry : cosDictionary.entrySet()) { ret.put(getName(entry.getKey()), convertOne(entry.getValue())); } return ret; }
From source file:org.xstudiosys.pdfxmp.XMPUtil.java
License:Open Source License
/** * Helper function for retrieving a BibtexEntry from the * PDDocumentInformation in a PDF file.//from ww w . j av a2 s .co m * * To understand how to get hold of a PDDocumentInformation have a look in * the test cases for XMPUtil. * * The BibtexEntry is build by mapping individual fields in the document * information (like author, title, keywords) to fields in a bibtex entry. * * @param di * The document information from which to build a BibtexEntry. * * @return The bibtex entry found in the document information. */ @SuppressWarnings("unchecked") public static BibtexEntry getBibtexEntryFromDocumentInformation(PDDocumentInformation di) { BibtexEntry entry = new BibtexEntry(); String s = di.getAuthor(); if (s != null) entry.setField("author", s); s = di.getTitle(); if (s != null) entry.setField("title", s); s = di.getKeywords(); if (s != null) entry.setField("keywords", s); s = di.getSubject(); if (s != null) entry.setField("abstract", s); COSDictionary dict = di.getDictionary(); for (Map.Entry<COSName, COSBase> o : dict.entrySet()) { String key = o.getKey().getName(); if (key.startsWith("bibtex/")) { String value = dict.getString(key); key = key.substring("bibtex/".length()); if (key.equals("entrytype")) { BibtexEntryType type = BibtexEntryType.getStandardType(value); if (type != null) entry.setType(type); } else entry.setField(key, value); } } // Return null if no values were found return (entry.getAllFields().size() > 0 ? entry : null); }
From source file:se.streamsource.streamflow.web.application.pdf.Underlay.java
License:Apache License
/** * merges two dictionaries.//from ww w.j a v a 2 s . c o m * * @param dest * @param source */ private void mergeDictionary(COSName name, COSDictionary dest, COSDictionary source, Map objectNameMap) { COSDictionary destDict = (COSDictionary) dest.getDictionaryObject(name); COSDictionary sourceDict = (COSDictionary) source.getDictionaryObject(name); if (destDict == null) { destDict = new COSDictionary(); dest.setItem(name, destDict); } if (sourceDict != null) { for (Map.Entry<COSName, COSBase> entry : sourceDict.entrySet()) { COSName mappedKey = (COSName) objectNameMap.get(entry.getKey().getName()); if (mappedKey != null) { destDict.setItem(mappedKey, entry.getValue()); } } } }