List of usage examples for org.apache.pdfbox.pdmodel PDDocumentInformation setCustomMetadataValue
public void setCustomMetadataValue(String fieldName, String fieldValue)
From source file:net.sf.jabref.logic.xmp.XMPUtil.java
License:Open Source License
/** * Try to write the given BibTexEntry in the Document Information (the * properties of the pdf)./*from w ww . j a v a 2 s . c o m*/ * * Existing fields values are overriden if the bibtex entry has the * corresponding value set. * * @param document * The pdf document to write to. * @param entry * The Bibtex entry that is written into the PDF properties. * * @param database * maybenull An optional database which the given bibtex entries * belong to, which will be used to resolve strings. If the * database is null the strings will not be resolved. */ private static void writeDocumentInformation(PDDocument document, BibEntry entry, BibDatabase database) { PDDocumentInformation di = document.getDocumentInformation(); BibEntry resolvedEntry; if (database == null) { resolvedEntry = entry; } else { resolvedEntry = database.resolveForStrings(entry, false); } // Query privacy filter settings JabRefPreferences prefs = JabRefPreferences.getInstance(); boolean useXmpPrivacyFilter = prefs.getBoolean(JabRefPreferences.USE_XMP_PRIVACY_FILTER); // Fields for which not to write XMP data later on: Set<String> filters = new TreeSet<>(prefs.getStringList(JabRefPreferences.XMP_PRIVACY_FILTERS)); // Set all the values including key and entryType Set<String> fields = resolvedEntry.getFieldNames(); for (String field : fields) { if (useXmpPrivacyFilter && filters.contains(field)) { // erase field instead of adding it if ("author".equals(field)) { di.setAuthor(null); } else if ("title".equals(field)) { di.setTitle(null); } else if ("keywords".equals(field)) { di.setKeywords(null); } else if ("abstract".equals(field)) { di.setSubject(null); } else { di.setCustomMetadataValue("bibtex/" + field, null); } continue; } if ("author".equals(field)) { di.setAuthor(resolvedEntry.getField("author")); } else if ("title".equals(field)) { di.setTitle(resolvedEntry.getField("title")); } else if ("keywords".equals(field)) { di.setKeywords(resolvedEntry.getField("keywords")); } else if ("abstract".equals(field)) { di.setSubject(resolvedEntry.getField("abstract")); } else { di.setCustomMetadataValue("bibtex/" + field, resolvedEntry.getField(field)); } } di.setCustomMetadataValue("bibtex/entrytype", EntryUtil.capitalizeFirst(resolvedEntry.getType())); }
From source file:net.sf.jabref.util.XMPUtil.java
License:Open Source License
/** * Try to write the given BibTexEntry in the Document Information (the * properties of the pdf)./*from w ww.ja va2 s .co m*/ * * Existing fields values are overriden if the bibtex entry has the * corresponding value set. * * @param document * The pdf document to write to. * @param entry * The Bibtex entry that is written into the PDF properties. * * @param database * maybenull An optional database which the given bibtex entries * belong to, which will be used to resolve strings. If the * database is null the strings will not be resolved. */ private static void writeDocumentInformation(PDDocument document, BibtexEntry entry, BibtexDatabase database) { PDDocumentInformation di = document.getDocumentInformation(); if (database != null) { entry = database.resolveForStrings(entry, false); } // Query privacy filter settings JabRefPreferences prefs = JabRefPreferences.getInstance(); boolean useXmpPrivacyFilter = prefs.getBoolean(JabRefPreferences.USE_XMP_PRIVACY_FILTER); // Fields for which not to write XMP data later on: TreeSet<String> filters = new TreeSet<String>( Arrays.asList(prefs.getStringArray(JabRefPreferences.XMP_PRIVACY_FILTERS))); // Set all the values including key and entryType Set<String> fields = entry.getAllFields(); for (String field : fields) { if (useXmpPrivacyFilter && filters.contains(field)) { // erase field instead of adding it if (field.equals("author")) { di.setAuthor(null); } else if (field.equals("title")) { di.setTitle(null); } else if (field.equals("keywords")) { di.setKeywords(null); } else if (field.equals("abstract")) { di.setSubject(null); } else { di.setCustomMetadataValue("bibtex/" + field, null); } continue; } if (field.equals("author")) { di.setAuthor(entry.getField("author")); } else if (field.equals("title")) { di.setTitle(entry.getField("title")); } else if (field.equals("keywords")) { di.setKeywords(entry.getField("keywords")); } else if (field.equals("abstract")) { di.setSubject(entry.getField("abstract")); } else { di.setCustomMetadataValue("bibtex/" + field, entry.getField(field)); } } di.setCustomMetadataValue("bibtex/entrytype", entry.getType().getName()); }
From source file:org.crossref.pdfmark.Main.java
License:Open Source License
public static void writeInfoDictionary(FileInputStream in, String outputFile, byte[] xmp) throws IOException, COSVisitorException { PDFParser parser = new PDFParser(in); parser.parse();/*from www . j a v a2 s . co m*/ PDDocument document = parser.getPDDocument(); PDDocumentInformation info = document.getDocumentInformation(); for (Entry<String, String> entry : XmpUtils.toInfo(xmp).entrySet()) { info.setCustomMetadataValue(entry.getKey(), entry.getValue()); } document.setDocumentInformation(info); document.save(outputFile); document.close(); }
From source file:org.lockss.plugin.georgthiemeverlag.GeorgThiemeVerlagPdfFilterFactory.java
License:Open Source License
@Override public void transform(ArchivalUnit au, PdfDocument pdfDocument) throws PdfException { pdfDocument.unsetModificationDate(); PdfUtil.normalizeTrailerId(pdfDocument); pdfDocument.unsetMetadata();//from w w w . j a v a 2 s .c om PDDocumentInformation pdDocInfo = ((GtvPdfBoxDocument) pdfDocument).getPdDocumentInformation(); if (pdDocInfo.getCustomMetadataValue(GtvPdfBoxDocument.PDFDATE) != null) { pdDocInfo.setCustomMetadataValue(GtvPdfBoxDocument.PDFDATE, null); } if (pdDocInfo.getCustomMetadataValue(GtvPdfBoxDocument.PDFUSER) != null) { pdDocInfo.setCustomMetadataValue(GtvPdfBoxDocument.PDFUSER, null); } PdfStateMachineWorker worker = new PdfStateMachineWorker(); boolean anyXform = false; for (PdfPage pdfPage : pdfDocument.getPages()) { PdfTokenStream pdfTokenStream = pdfPage.getPageTokenStream(); worker.process(pdfTokenStream); if (worker.getResult()) { anyXform = true; List<PdfToken> tokens = pdfTokenStream.getTokens(); // clear tokens including text markers tokens.subList(worker.getBegin(), worker.getEnd() + 1).clear(); pdfTokenStream.setTokens(tokens); } } if (log.isDebug2()) { log.debug2("Transform: " + anyXform); } }
From source file:org.pdfmetamodifier.MetadataHelper.java
License:Apache License
/** * Convert list of lines to Metadata object. * //from w w w .j a va 2 s. c o m * @param lineList * Source list of lines with Metadata representation. * @return Metadata object. */ public static PDDocumentInformation stringListToMetadata(final List<String> lineList) { final PDDocumentInformation documentInformation = new PDDocumentInformation(); if (lineList != null) { for (String line : lineList) { final Matcher matcher = METADATA_LINE_PATTERN.matcher(line); if (!matcher.matches()) { throw new IllegalArgumentException( String.format("Metadata line have a wrong format: '%s'!", line)); } documentInformation.setCustomMetadataValue(matcher.group("key"), matcher.group("value")); } } return documentInformation; }
From source file:org.primaresearch.pdf.PageToPdfConverterUsingPdfBox.java
License:Apache License
private void addMetadata(PDDocument doc, Page page) { MetaData pageMetadata = page.getMetaData(); PDDocumentInformation info = new PDDocumentInformation(); //Creator//from w w w. j a v a2 s. c o m if (pageMetadata.getCreator() != null && !pageMetadata.getCreator().isEmpty()) info.setCreator(pageMetadata.getCreator()); //Comments if (pageMetadata.getComments() != null && !pageMetadata.getComments().isEmpty()) info.setCustomMetadataValue("Comments", pageMetadata.getComments()); //TODO doc.setDocumentInformation(info); }
From source file:org.sejda.impl.pdfbox.SetMetadataTask.java
License:Apache License
public void execute(SetMetadataParameters parameters) throws TaskException { notifyEvent(getNotifiableTaskMetadata()).progressUndetermined(); PdfSource<?> source = parameters.getSource(); LOG.debug("Opening {}", source); documentHandler = source.open(documentLoader); documentHandler.setCreatorOnPDDocument(); File tmpFile = createTemporaryPdfBuffer(); LOG.debug("Created output temporary buffer {}", tmpFile); LOG.debug("Setting metadata on temporary document."); PDDocumentInformation actualMeta = documentHandler.getUnderlyingPDDocument().getDocumentInformation(); for (Entry<PdfMetadataKey, String> meta : parameters.entrySet()) { LOG.trace("'{}' -> '{}'", meta.getKey().getKey(), meta.getValue()); actualMeta.setCustomMetadataValue(meta.getKey().getKey(), meta.getValue()); }/* w w w . j av a 2 s .com*/ documentHandler.setVersionOnPDDocument(parameters.getVersion()); documentHandler.compressXrefStream(parameters.isCompress()); documentHandler.saveDecryptedPDDocument(tmpFile); nullSafeCloseQuietly(documentHandler); outputWriter.setOutput(file(tmpFile).name(parameters.getOutputName())); parameters.getOutput().accept(outputWriter); LOG.debug("Metadata set on {}", parameters.getOutput()); }
From source file:org.xstudiosys.pdfxmp.XMPUtil.java
License:Open Source License
/** * Try to write the given BibTexEntry in the Document Information (the * properties of the pdf).// w ww . jav a 2s. co m * * Existing fields values are overriden if the bibtex entry has the * corresponding value set. * * @param document * The pdf document to write to. * @param entry * The Bibtex entry that is written into the PDF properties. * * @param database * maybenull An optional database which the given bibtex entries * belong to, which will be used to resolve strings. If the * database is null the strings will not be resolved. */ public static void writeDocumentInformation(PDDocument document, BibtexEntry entry, BibtexDatabase database) { PDDocumentInformation di = document.getDocumentInformation(); if (database != null) entry = database.resolveForStrings(entry, false); // Query privacy filter settings /* JabRefPreferences prefs = JabRefPreferences.getInstance(); boolean useXmpPrivacyFilter = prefs.getBoolean("useXmpPrivacyFilter"); // Fields for which not to write XMP data later on: TreeSet<String> filters = new TreeSet<String>(Arrays.asList(prefs.getStringArray(JabRefPreferences.XMP_PRIVACY_FILTERS))); */ // Set all the values including key and entryType Set<String> fields = entry.getAllFields(); for (String field : fields) { /* if (useXmpPrivacyFilter && filters.contains(field)) { // erase field instead of adding it if (field.equals("author")) { di.setAuthor(null); } else if (field.equals("title")) { di.setTitle(null); } else if (field.equals("keywords")) { di.setKeywords(null); } else if (field.equals("abstract")) { di.setSubject(null); } else { di.setCustomMetadataValue("bibtex/" + field, null); } continue; } */ if (field.equals("author")) { di.setAuthor(entry.getField("author")); } else if (field.equals("title")) { di.setTitle(entry.getField("title")); } else if (field.equals("keywords")) { di.setKeywords(entry.getField("keywords")); } else if (field.equals("abstract")) { di.setSubject(entry.getField("abstract")); } else { di.setCustomMetadataValue("bibtex/" + field, entry.getField(field)); } } di.setCustomMetadataValue("bibtex/entrytype", entry.getType().getName()); }