private void extractEmbeddedDocuments(PDDocument document) throws IOException, SAXException, TikaException { PDDocumentNameDictionary namesDictionary = new PDDocumentNameDictionary(document.getDocumentCatalog()); PDEmbeddedFilesNameTreeNode efTree = namesDictionary.getEmbeddedFiles(); if (efTree == null) { return; } Map<String, PDComplexFileSpecification> embeddedFileNames = efTree.getNames(); //For now, try to get the embeddedFileNames out of embeddedFiles or its kids. //This code follows: pdfbox/examples/pdmodel/ExtractEmbeddedFiles.java //If there is a need we could add a fully recursive search to find a non-null //Map<String, COSObjectable> that contains the doc info. if (embeddedFileNames != null) { processEmbeddedDocNames(embeddedFileNames); } else { List<PDNameTreeNode<PDComplexFileSpecification>> kids = efTree.getKids(); if (kids == null) { return; } for (PDNameTreeNode<PDComplexFileSpecification> node : kids) { embeddedFileNames = node.getNames(); if (embeddedFileNames != null) { processEmbeddedDocNames(embeddedFileNames); } } } }
/** * A Catalog shall not contain the EmbeddedFiles entry. * * @param ctx * @throws ValidationException */ protected void validateNames(PreflightContext ctx) throws ValidationException { PDDocumentNameDictionary names = catalog.getNames(); if (names != null) { PDEmbeddedFilesNameTreeNode efs = names.getEmbeddedFiles(); if (efs != null) { addValidationError(ctx, new ValidationError(ERROR_SYNTAX_TRAILER_CATALOG_EMBEDDEDFILES, "EmbeddedFile entry is present in the Names dictionary")); } if (names.getJavaScript() != null) { addValidationError(ctx, new ValidationError(ERROR_ACTION_FORBIDDEN_ACTIONS_NAMED, "Javascript entry is present in the Names dictionary")); } } }
if (namesDict != null) PDDestinationNameTreeNode destsTree = namesDict.getDests(); if (destsTree != null)
efTree.setKids(kids); PDDocumentNameDictionary names = new PDDocumentNameDictionary( doc.getDocumentCatalog() ); names.setEmbeddedFiles( efTree ); doc.getDocumentCatalog().setNames( names );
if (names != null) PDEmbeddedFilesNameTreeNode embeddedFiles = names.getEmbeddedFiles(); if (embeddedFiles != null)
PDDocumentNameDictionary names = new PDDocumentNameDictionary(doc.getDocumentCatalog()); PDEmbeddedFilesNameTreeNode efTree = names.getEmbeddedFiles(); if (efTree == null) { efTree = new PDEmbeddedFilesNameTreeNode(); efTree.setNames(namesMap); names.setEmbeddedFiles(efTree); doc.getDocumentCatalog().setNames(names);
private void sanitizeNamed(PDDocument doc, PDDocumentNameDictionary names) { if (names == null) { return; } new PDEmbeddedFileBleach(this, doc).sanitize(names.getEmbeddedFiles()); if (names.getJavaScript() != null) { recordJavascriptThreat("Named JavaScriptAction", "Action"); names.setJavascript(null); } }
/** * @return The names dictionary for this document or null if none exist. */ public PDDocumentNameDictionary getNames() { COSDictionary names = (COSDictionary) root.getDictionaryObject(COSName.NAMES); return names == null ? null : new PDDocumentNameDictionary(this, names); }
PDDocument pd; File input = new File(inputfile); // Input File pd = PDDocument.load(input); //Writes all embedded Filenames (from pdf document) into Logfile try{ PDDocumentCatalog catalog = pd.getDocumentCatalog(); PDDocumentNameDictionary names = catalog.getNames(); PDEmbeddedFilesNameTreeNode embeddedFiles = names.getEmbeddedFiles(); Map<String, COSObjectable> embeddedFileNames = embeddedFiles.getNames(); //For-Each Loop is used to list all embedded files (if there is more than one) for (Map.Entry<String, COSObjectable> entry : embeddedFileNames.entrySet()) { //You might need to configure the logger first logger.info("Inputfile: " + inputfile +"Found embedded File: " + entry.getKey() + ":"); } } catch (Exception e){ System.out.println("Document has no attachments. "); }
efTree.setKids(kids); PDDocumentNameDictionary names = new PDDocumentNameDictionary( doc.getDocumentCatalog() ); names.setEmbeddedFiles( efTree ); doc.getDocumentCatalog().setNames( names );
/** * @return The names dictionary for this document or null if none exist. */ public PDDocumentNameDictionary getNames() { COSDictionary names = (COSDictionary) root.getDictionaryObject(COSName.NAMES); return names == null ? null : new PDDocumentNameDictionary(this, names); }
document = PDDocument.load(pdfFile ); PDDocumentNameDictionary namesDictionary = new PDDocumentNameDictionary( document.getDocumentCatalog() ); PDEmbeddedFilesNameTreeNode efTree = namesDictionary.getEmbeddedFiles(); if (efTree != null)
private void reportEmbeddedFiles(PDDocumentCatalog catalog) { int index = 0; PDEmbeddedFilesNameTreeNode efTree = catalog.getNames().getEmbeddedFiles(); try { if (config.isFeatureEnabled(FeatureObjectType.EMBEDDED_FILE) && efTree.getNames() != null) { for (PDComplexFileSpecification file : efTree.getNames().values()) { reporter.report(PBFeaturesObjectCreator.createEmbeddedFileFeaturesObject(file, ++index)); } } } catch (IOException e) { LOGGER.debug("Error creating PDFBox SubType.", e); handleSubtypeCreationProblem(e.getMessage()); } if (efTree.getKids() != null) { for (PDNameTreeNode<PDComplexFileSpecification> tree : efTree.getKids()) { if (tree != null) { index = reportEmbeddedFileNode(tree, index); } } } }
/** * A Catalog shall not contain the EmbeddedFiles entry. * * @param ctx * @throws ValidationException */ protected void validateNames(PreflightContext ctx) throws ValidationException { PDDocumentNameDictionary names = catalog.getNames(); if (names != null) { PDEmbeddedFilesNameTreeNode efs = names.getEmbeddedFiles(); if (efs != null) { addValidationError(ctx, new ValidationError(ERROR_SYNTAX_TRAILER_CATALOG_EMBEDDEDFILES, "EmbeddedFile entry is present in the Names dictionary")); } if (names.getJavaScript() != null) { addValidationError(ctx, new ValidationError(ERROR_ACTION_FORBIDDEN_ACTIONS_NAMED, "Javascript entry is present in the Names dictionary")); } } }
/** * @return The names dictionary for this document or null if none exist. */ public PDDocumentNameDictionary getNames() { COSDictionary names = (COSDictionary) root.getDictionaryObject(COSName.NAMES); return names == null ? null : new PDDocumentNameDictionary(this, names); }
if (namesDict != null) PDDestinationNameTreeNode destsTree = namesDict.getDests(); if (destsTree != null)
private void extractEmbeddedDocuments(PDDocument document) throws IOException, SAXException, TikaException { PDDocumentNameDictionary namesDictionary = new PDDocumentNameDictionary(document.getDocumentCatalog()); PDEmbeddedFilesNameTreeNode efTree = namesDictionary.getEmbeddedFiles(); if (efTree == null) { return; } Map<String, PDComplexFileSpecification> embeddedFileNames = efTree.getNames(); //For now, try to get the embeddedFileNames out of embeddedFiles or its kids. //This code follows: pdfbox/examples/pdmodel/ExtractEmbeddedFiles.java //If there is a need we could add a fully recursive search to find a non-null //Map<String, COSObjectable> that contains the doc info. if (embeddedFileNames != null) { processEmbeddedDocNames(embeddedFileNames); } else { List<PDNameTreeNode<PDComplexFileSpecification>> kids = efTree.getKids(); if (kids == null) { return; } for (PDNameTreeNode<PDComplexFileSpecification> node : kids) { embeddedFileNames = node.getNames(); if (embeddedFileNames != null) { processEmbeddedDocNames(embeddedFileNames); } } } }
PDDocumentNameDictionary namesDictionary = new PDDocumentNameDictionary( document.getDocumentCatalog() ); PDEmbeddedFilesNameTreeNode efTree = namesDictionary.getEmbeddedFiles(); if (efTree != null)
/** * A Catalog shall not contain the EmbeddedFiles entry. * * @param ctx * @throws ValidationException */ protected void validateNames(PreflightContext ctx) throws ValidationException { PDDocumentNameDictionary names = catalog.getNames(); if (names != null) { PDEmbeddedFilesNameTreeNode efs = names.getEmbeddedFiles(); if (efs != null) { addValidationError(ctx, new ValidationError(ERROR_SYNTAX_TRAILER_CATALOG_EMBEDDEDFILES, "EmbeddedFile entry is present in the Names dictionary")); } if (names.getJavaScript() != null) { addValidationError(ctx, new ValidationError(ERROR_ACTION_FORBIDDEN_ACTIONS_NAMED, "Javascript entry is present in the Names dictionary")); } } }
if (namesDict != null) PDDestinationNameTreeNode destsTree = namesDict.getDests(); if (destsTree != null)