List of usage examples for org.apache.pdfbox.pdmodel PDDocumentInformation getProducer
public String getProducer()
From source file:PDFExtractMetadata.java
License:Apache License
private static void showDocumentInformation(PDDocumentInformation information) { display("Title:", information.getTitle()); display("Subject:", information.getSubject()); display("Author:", information.getAuthor()); display("Creator:", information.getCreator()); display("Producer:", information.getProducer()); }
From source file:adams.flow.transformer.PDFMetaData.java
License:Open Source License
/** * Executes the flow item./*from w w w .ja va 2 s .c o m*/ * * @return null if everything is fine, otherwise error message */ @Override protected String doExecute() { String result; File file; SpreadSheet sheet; PDDocument document; PDDocumentInformation info; Row row; Set<String> keys; result = null; // get file if (m_InputToken.getPayload() instanceof File) file = (File) m_InputToken.getPayload(); else file = new PlaceholderFile((String) m_InputToken.getPayload()); sheet = new DefaultSpreadSheet(); sheet.setDataRowClass(SparseDataRow.class); sheet.setName("Meta-Data: " + file.getAbsolutePath()); try { row = sheet.addRow(); document = PDDocument.load(file.getAbsoluteFile()); info = document.getDocumentInformation(); addCell(row, "Title", info.getTitle()); addCell(row, "Subject", info.getSubject()); addCell(row, "Author", info.getAuthor()); addCell(row, "Keywords", info.getKeywords()); addCell(row, "Producer", info.getProducer()); addCell(row, "Creation Date", info.getCreationDate()); addCell(row, "Modification Date", info.getModificationDate()); addCell(row, "Creator", info.getCreator()); addCell(row, "Trapped", info.getTrapped()); keys = info.getMetadataKeys(); for (String key : keys) addCell(row, "Meta-" + key, info.getCustomMetadataValue(key)); } catch (Exception e) { result = handleException("Failed to extract meta-data: ", e); } if (result == null) m_OutputToken = new Token(sheet); return result; }
From source file:com.esri.geoportal.commons.pdf.PdfUtils.java
License:Apache License
/** * Reads metadata values from a PDF file. * /* w ww . j a v a 2 s . com*/ * @param rawBytes the PDF to read * @param defaultTitle title to be used if the PDF metadata doesn't have one * @param geometryServiceUrl url of a <a href="https://developers.arcgis.com/rest/services-reference/geometry-service.htm">geometry service</a> for reprojecting coordinates. * * @return metadata properties or null if the PDF cannot be read. * * @throws IOException on parsing error */ public static Properties readMetadata(byte[] rawBytes, String defaultTitle, String geometryServiceUrl) throws IOException { Properties ret = new Properties(); // Attempt to read in the PDF file try (PDDocument document = PDDocument.load(rawBytes)) { // See if we can read the PDF if (!document.isEncrypted()) { // Get document metadata PDDocumentInformation info = document.getDocumentInformation(); if (info != null) { if (info.getTitle() != null) { ret.put(PROP_TITLE, info.getTitle()); } else { ret.put(PROP_TITLE, defaultTitle); } if (info.getSubject() != null) { ret.put(PROP_SUBJECT, info.getSubject()); } else { StringBuilder psudoSubject = new StringBuilder(""); psudoSubject.append("\nAuthor: " + info.getAuthor()); psudoSubject.append("\nCreator: " + info.getCreator()); psudoSubject.append("\nProducer: " + info.getProducer()); ret.put(PROP_SUBJECT, psudoSubject.toString()); } if (info.getModificationDate() != null) { ret.put(PROP_MODIFICATION_DATE, info.getModificationDate().getTime()); } else { ret.put(PROP_MODIFICATION_DATE, info.getCreationDate().getTime()); } } else { LOG.warn("Got null metadata for PDF file"); return null; } // Attempt to read in geospatial PDF data COSObject measure = document.getDocument().getObjectByType(COSName.getPDFName("Measure")); String bBox = null; if (measure != null) { // This is a Geospatial PDF (i.e. Adobe's standard) COSDictionary dictionary = (COSDictionary) measure.getObject(); float[] coords = ((COSArray) dictionary.getItem("GPTS")).toFloatArray(); bBox = generateBbox(coords); } else { PDPage page = document.getPage(0); if (page.getCOSObject().containsKey(COSName.getPDFName("LGIDict"))) { // This is a GeoPDF (i.e. TerraGo's standard) bBox = extractGeoPDFProps(page, geometryServiceUrl); } } if (bBox != null) { ret.put(PROP_BBOX, bBox); } } else { LOG.warn("Cannot read encrypted PDF file"); return null; } } catch (IOException ex) { LOG.error("Exception reading PDF", ex); throw ex; } return ret; }
From source file:com.github.joemcintyre.pdffinish.PDFFinish.java
License:Open Source License
/** * Show metadata from PDF document./*w w w . j a va 2 s. c om*/ * * @param document Loaded PDF document. */ private static void showMetadata(PDDocument document) throws IOException { PDDocumentInformation info = document.getDocumentInformation(); System.out.println("Title: " + info.getTitle()); System.out.println("Author: " + info.getAuthor()); System.out.println("Subject: " + info.getSubject()); System.out.println("Keywords: " + info.getKeywords()); System.out.println("Creator: " + info.getCreator()); System.out.println("Producer: " + info.getProducer()); System.out.println("Creation Date: " + info.getCreationDate()); System.out.println("Modification Date: " + info.getModificationDate()); }
From source file:com.jaeksoft.searchlib.parser.PdfParser.java
License:Open Source License
private void extractMetaData(ParserResultItem result, PDDocument pdf) throws IOException { PDDocumentInformation info = pdf.getDocumentInformation(); if (info != null) { result.addField(ParserFieldEnum.title, info.getTitle()); result.addField(ParserFieldEnum.subject, info.getSubject()); result.addField(ParserFieldEnum.author, info.getAuthor()); result.addField(ParserFieldEnum.producer, info.getProducer()); result.addField(ParserFieldEnum.keywords, info.getKeywords()); String d = getDate(getCreationDate(info)); if (d != null) result.addField(ParserFieldEnum.creation_date, d); d = getDate(getModificationDate(info)); if (d != null) result.addField(ParserFieldEnum.modification_date, d); }// w w w .j a va 2 s . c o m int pages = pdf.getNumberOfPages(); result.addField(ParserFieldEnum.number_of_pages, pages); PDDocumentCatalog catalog = pdf.getDocumentCatalog(); if (catalog != null) { result.addField(ParserFieldEnum.language, catalog.getLanguage()); } }
From source file:com.openkm.util.metadata.MetadataExtractor.java
License:Open Source License
/** * Extract metadata from PDF/* ww w .j a v a 2 s . c o m*/ */ public static PdfMetadata pdfExtractor(InputStream is) throws IOException { PDDocument doc = PDDocument.load(is); PDDocumentInformation info = doc.getDocumentInformation(); PdfMetadata md = new PdfMetadata(); md.setNumberOfPages(doc.getNumberOfPages()); md.setTitle(info.getTitle()); md.setAuthor(info.getAuthor()); md.setSubject(info.getSubject()); md.setKeywords(info.getKeywords()); md.setCreator(info.getCreator()); md.setProducer(info.getProducer()); md.setTrapped(info.getTrapped()); md.setCreationDate(info.getCreationDate()); md.setModificationDate(info.getModificationDate()); log.info("pdfExtractor: {}", md); return md; }
From source file:com.opensearchserver.extractor.parser.PdfBox.java
License:Apache License
private void extractMetaData(PDDocument pdf) throws IOException { PDDocumentInformation info = pdf.getDocumentInformation(); if (info != null) { metas.add(TITLE, info.getTitle()); metas.add(SUBJECT, info.getSubject()); metas.add(AUTHOR, info.getAuthor()); metas.add(PRODUCER, info.getProducer()); metas.add(KEYWORDS, info.getKeywords()); metas.add(CREATION_DATE, getDate(getCreationDate(info))); metas.add(MODIFICATION_DATE, getModificationDate(info)); }/*from ww w. ja v a2 s.c o m*/ int pages = pdf.getNumberOfPages(); metas.add(NUMBER_OF_PAGES, pages); PDDocumentCatalog catalog = pdf.getDocumentCatalog(); if (catalog != null) metas.add(LANGUAGE, catalog.getLanguage()); }
From source file:com.qwazr.library.pdfbox.PdfBoxParser.java
License:Apache License
private void extractMetaData(final PDDocument pdf, final ParserFieldsBuilder metas) { metas.set(MIME_TYPE, DEFAULT_MIMETYPES[0]); final PDDocumentInformation info = pdf.getDocumentInformation(); if (info != null) { metas.add(TITLE, info.getTitle()); metas.add(SUBJECT, info.getSubject()); metas.add(AUTHOR, info.getAuthor()); metas.add(PRODUCER, info.getProducer()); metas.add(KEYWORDS, info.getKeywords()); metas.add(CREATION_DATE, info.getCreationDate()); metas.add(MODIFICATION_DATE, info.getModificationDate()); }//from w w w . ja v a 2 s . c o m int pages = pdf.getNumberOfPages(); metas.add(NUMBER_OF_PAGES, pages); PDDocumentCatalog catalog = pdf.getDocumentCatalog(); if (catalog != null) metas.add(LANGUAGE, catalog.getLanguage()); }
From source file:com.wintindustries.pdffilter.pdfcore.PDFTester.java
static public void printMetadata(PDDocument document) throws IOException { PDDocumentInformation info = document.getDocumentInformation(); PDDocumentCatalog cat = document.getDocumentCatalog(); PDMetadata metadata = cat.getMetadata(); System.out.println("Page Count=" + document.getNumberOfPages()); System.out.println("Title=" + info.getTitle()); System.out.println("Author=" + info.getAuthor()); System.out.println("Subject=" + info.getSubject()); System.out.println("Keywords=" + info.getKeywords()); System.out.println("Creator=" + info.getCreator()); System.out.println("Producer=" + info.getProducer()); System.out.println("Creation Date=" + formatDate(info.getCreationDate())); System.out.println("Modification Date=" + formatDate(info.getModificationDate())); System.out.println("Trapped=" + info.getTrapped()); if (metadata != null) { System.out.println("Metadata=" + metadata.getInputStreamAsString()); }//from ww w. j ava 2 s. c o m }
From source file:de.offis.health.icardea.cied.pdf.extractor.PDFApachePDFBoxExtractor.java
License:Apache License
/** * This method will return the key and value pairs stored in the PDF * information. It's the basic information like title, subject, author, * creator, keywords, producer (meaning application) as well as creation * and modification date. The method is provided for debugging purposes. * /*from w w w . j a v a 2s.c om*/ * @return Returns <code>key=value</code> pair line by line (using system * dependent newline). */ @SuppressWarnings("unused") private String getPdfInfo() { StringBuffer stringBuffer = new StringBuffer(); if (pdfDocument != null) { PDDocumentInformation pdfInfo = pdfDocument.getDocumentInformation(); // Title if (pdfInfo.getTitle() != null) { stringBuffer.append("Title"); stringBuffer.append("="); stringBuffer.append(pdfInfo.getTitle()); stringBuffer.append(GlobalTools.LINESEPARATOR); } // end if // Subject if (pdfInfo.getSubject() != null) { stringBuffer.append("Subject"); stringBuffer.append("="); stringBuffer.append(pdfInfo.getSubject()); stringBuffer.append(GlobalTools.LINESEPARATOR); } // end if // Keywords if (pdfInfo.getKeywords() != null) { stringBuffer.append("Keywords"); stringBuffer.append("="); stringBuffer.append(pdfInfo.getKeywords()); stringBuffer.append(GlobalTools.LINESEPARATOR); } // end if // Author if (pdfInfo.getAuthor() != null) { stringBuffer.append("Author"); stringBuffer.append("="); stringBuffer.append(pdfInfo.getAuthor()); stringBuffer.append(GlobalTools.LINESEPARATOR); } // end if // Producer if (pdfInfo.getProducer() != null) { stringBuffer.append("Producer"); stringBuffer.append("="); stringBuffer.append(pdfInfo.getProducer()); stringBuffer.append(GlobalTools.LINESEPARATOR); } // end if // Creator if (pdfInfo.getCreator() != null) { stringBuffer.append("Creator"); stringBuffer.append("="); stringBuffer.append(pdfInfo.getCreator()); stringBuffer.append(GlobalTools.LINESEPARATOR); } // end if // CreationDate try { if (pdfInfo.getCreationDate() != null) { stringBuffer.append("CreationDate"); stringBuffer.append("="); stringBuffer.append(GlobalTools.calendar2String(pdfInfo.getCreationDate(), GlobalTools.DATE_FORMAT_STRING_ISO8601)); stringBuffer.append(GlobalTools.LINESEPARATOR); } // end if } catch (IOException ex) { } // end try..catch // ModDate try { if (pdfInfo.getModificationDate() != null) { stringBuffer.append("ModDate"); stringBuffer.append("="); stringBuffer.append(GlobalTools.calendar2String(pdfInfo.getModificationDate(), GlobalTools.DATE_FORMAT_STRING_ISO8601)); stringBuffer.append(GlobalTools.LINESEPARATOR); } // end if } catch (IOException ex) { } // end try..catch } // end if return stringBuffer.toString(); }