@Test public void embeddedFileAndJavascriptTest() throws IOException { PdfDocument pdfDocument = new PdfDocument(new PdfReader(sourceFolder + "FileWithSingleAttachment.pdf")); PdfNameTree embeddedFilesNameTree = pdfDocument.getCatalog().getNameTree(PdfName.EmbeddedFiles); Map<String, PdfObject> objs = embeddedFilesNameTree.getNames(); PdfNameTree javascript = pdfDocument.getCatalog().getNameTree(PdfName.JavaScript); Map<String, PdfObject> objs2 = javascript.getNames(); pdfDocument.close(); Assert.assertEquals(1, objs.size()); Assert.assertEquals(1, objs2.size()); }
public Map<String, PdfObject> getNames() { if (items.size() > 0) { return items; } PdfDictionary dictionary = catalog.getPdfObject().getAsDictionary(PdfName.Names); if (dictionary != null) { dictionary = dictionary.getAsDictionary(treeType); if (dictionary != null) { items = readTree(dictionary); Set<String> keys = new HashSet<>(); keys.addAll(items.keySet()); for (String key : keys) { if (treeType.equals(PdfName.Dests)) { PdfArray arr = getDestArray(items.get(key)); if (arr != null) { items.put(key, arr); } else items.remove(key); } else if (items.get(key) == null) items.remove(key); } } } if (treeType.equals(PdfName.Dests)) { PdfDictionary destinations = catalog.getPdfObject().getAsDictionary(PdfName.Dests); if (destinations != null) { Set<PdfName> keys = destinations.keySet(); for (PdfName key : keys) { PdfArray array = getDestArray(destinations.get(key)); if (array == null) { continue; } items.put(key.getValue(), array); } } } return items; }
PdfNameTree implements Serializable { public Map<String, PdfObject> getNames() { if (items.size() > 0) { return items; } PdfDictionary dictionary = catalog.getPdfObject().getAsDictionary(PdfName.Names); if (dictionary != null) { dictionary = dictionary.getAsDictionary(treeType); if (dictionary != null) { items = readTree(dictionary); Set<String> keys = new HashSet<>(); keys.addAll(items.keySet()); for (String key : keys) { if (treeType.equals(PdfName.Dests)) { PdfArray arr = getDestArray(items.get(key)); if (arr != null) { items.put(key, arr); } else items.remove(key); } else if (items.get(key) == null) items.remove(key); } } } if (treeType.equals(PdfName.Dests)) { PdfDictionary destinations = catalog.getPdfObject().getAsDictionary(PdfName.Dests); if (destinations != null) { Set<PdfName> keys = destinations.keySet(); for (PdfName key : keys) { PdfArray array = getDestArray(destinations.get(key)); if (array == null) { continue; } items.put(key.getValue(), array); } } } return items; } }
PdfNameTree implements Serializable { public Map<String, PdfObject> getNames() { if (items.size() > 0) { return items; } PdfDictionary dictionary = catalog.getPdfObject().getAsDictionary(PdfName.Names); if (dictionary != null) { dictionary = dictionary.getAsDictionary(treeType); if (dictionary != null) { items = readTree(dictionary); Set<String> keys = new HashSet<>(); keys.addAll(items.keySet()); for (String key : keys) { if (treeType.equals(PdfName.Dests)) { PdfArray arr = getDestArray(items.get(key)); if (arr != null) { items.put(key, arr); } else items.remove(key); } else if (items.get(key) == null) items.remove(key); } } } if (treeType.equals(PdfName.Dests)) { PdfDictionary destinations = catalog.getPdfObject().getAsDictionary(PdfName.Dests); if (destinations != null) { Set<PdfName> keys = destinations.keySet(); for (PdfName key : keys) { PdfArray array = getDestArray(destinations.get(key)); if (array == null) { continue; } items.put(key.getValue(), array); } } } return items; } PdfNameTree(PdfCatalog catalog, PdfName treeType); }
PdfNameTree implements Serializable { public Map<String, PdfObject> getNames() { if (items.size() > 0) { return items; } PdfDictionary dictionary = catalog.getPdfObject().getAsDictionary(PdfName.Names); if (dictionary != null) { dictionary = dictionary.getAsDictionary(treeType); if (dictionary != null) { items = readTree(dictionary); Set<String> keys = new HashSet<>(); keys.addAll(items.keySet()); for (String key : keys) { if (treeType.equals(PdfName.Dests)) { PdfArray arr = getDestArray(items.get(key)); if (arr != null) { items.put(key, arr); } else items.remove(key); } else if (items.get(key) == null) items.remove(key); } } } if (treeType.equals(PdfName.Dests)) { PdfDictionary destinations = catalog.getPdfObject().getAsDictionary(PdfName.Dests); if (destinations != null) { Set<PdfName> keys = destinations.keySet(); for (PdfName key : keys) { PdfArray array = getDestArray(destinations.get(key)); if (array == null) { continue; } items.put(key.getValue(), array); } } } return items; } PdfNameTree(PdfCatalog catalog, PdfName treeType); Map<String, PdfObject> getNames(); void addEntry(String key, PdfObject value); boolean isModified(); void setModified(); PdfDictionary buildTree(); }
PdfNameTree implements Serializable { public Map<String, PdfObject> getNames() { if (items.size() > 0) { return items; } PdfDictionary dictionary = catalog.getPdfObject().getAsDictionary(PdfName.Names); if (dictionary != null) { dictionary = dictionary.getAsDictionary(treeType); if (dictionary != null) { items = readTree(dictionary); Set<String> keys = new HashSet<>(); keys.addAll(items.keySet()); for (String key : keys) { if (treeType.equals(PdfName.Dests)) { PdfArray arr = getDestArray(items.get(key)); if (arr != null) { items.put(key, arr); } else items.remove(key); } else if (items.get(key) == null) items.remove(key); } } } if (treeType.equals(PdfName.Dests)) { PdfDictionary destinations = catalog.getPdfObject().getAsDictionary(PdfName.Dests); if (destinations != null) { Set<PdfName> keys = destinations.keySet(); for (PdfName key : keys) { PdfArray array = getDestArray(destinations.get(key)); if (array == null) { continue; } items.put(key.getValue(), array); } } } return items; } PdfNameTree(PdfCatalog catalog, PdfName treeType); Map<String, PdfObject> getNames(); void addEntry(String key, PdfObject value); boolean isModified(); void setModified(); PdfDictionary buildTree();  }