List of usage examples for com.lowagie.text Document getVersion
public static final String getVersion()
From source file:mesquite.lib.MesquitePDFFile.java
License:Open Source License
/** *@arg document Document object representing the output file * Add metadata to the PDF fle//from ww w . j av a 2s . c o m */ private void addMetaData(Document document) { document.addCreator( "Mesquite " + MesquiteModule.getMesquiteVersion() + " using portions of " + document.getVersion()); try { String uname = System.getProperty("user.name"); document.addAuthor(uname); } catch (SecurityException e) { document.addAuthor("Unknown"); } document.addKeywords("Mesquite"); // more later //document.addTitle(this.component.getParent().getName()); // ToDo: get the window's actual title }
From source file:net.mitnet.tools.pdf.book.publisher.BookPublisher.java
License:Open Source License
/** * Update PDF book with meta-data.//from w w w . java 2s . c o m * * @see http://itext-general.2136553.n4.nabble.com/how-to-add-meta-information-to-a-document-that-is-closed-td2137179.html * @see com.lowagie.examples.general.copystamp.AddWatermarkPageNumbers */ private void updatePdfBookWithMeta(File pdfBookFile) throws IOException, DocumentException { info("updating PDF book with meta ..."); File inputPdfFile = pdfBookFile; String inputPdfFilename = inputPdfFile.getAbsolutePath(); File outputPdfFile = File.createTempFile(DEFAULT_PDF_BOOK_FILE_NAME, FileExtensionConstants.PDF_EXTENSION); debug("outputPdfFile: " + outputPdfFile); String outputPdfFilename = outputPdfFile.getAbsolutePath(); PdfReader reader = new PdfReader(inputPdfFilename); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(outputPdfFilename)); HashMap metaMap = new HashMap(); String metaTitle = config.getMetaTitle(); addNonEmptyMapValue(metaMap, PdfMetaKeys.TITLE, metaTitle); String metaSubject = config.getMetaSubject(); addNonEmptyMapValue(metaMap, PdfMetaKeys.SUBJECT, metaSubject); String metaKeywords = config.getMetaKeywords(); addNonEmptyMapValue(metaMap, PdfMetaKeys.KEYWORDS, metaKeywords); String metaCreator = PDF_PUBLISHER_TOOLS_IDENT + " with " + Document.getVersion(); addNonEmptyMapValue(metaMap, PdfMetaKeys.CREATOR, metaCreator); String metaAuthor = config.getMetaAuthor(); addNonEmptyMapValue(metaMap, PdfMetaKeys.AUTHOR, metaAuthor); String metaVersionId = config.getMetaVersionId(); addNonEmptyMapValue(metaMap, PdfMetaKeys.VERSION_ID, metaVersionId); debug("updating PDF book with meta map: " + metaMap); stamper.setMoreInfo(metaMap); stamper.close(); if (outputPdfFile.exists()) { FileUtils.copyFile(outputPdfFile, pdfBookFile); FileUtils.deleteQuietly(outputPdfFile); } }
From source file:net.sf.jasperreports.engine.export.PdfXmpCreator.java
License:Open Source License
byte[] createXmpMetadata() { try {//w w w . j a v a2 s.co m XMPMeta xmp = XMPMetaFactory.create(); xmp.setObjectName(""); xmp.setProperty(XMPConst.NS_DC, DublinCoreSchema.FORMAT, FORMAT_PDF); xmp.setProperty(XMPConst.NS_PDF, PDF_PRODUCER, Document.getVersion()); if (pdfWriter.getPDFXConformance() == PdfWriter.PDFA1A) { xmp.setProperty(XMPConst.NS_PDFA_ID, PDFA_PART, PDFA_PART_1); xmp.setProperty(XMPConst.NS_PDFA_ID, PDFA_CONFORMANCE, PDFA_CONFORMANCE_A); } else if (pdfWriter.getPDFXConformance() == PdfWriter.PDFA1B) { xmp.setProperty(XMPConst.NS_PDFA_ID, PDFA_PART, PDFA_PART_1); xmp.setProperty(XMPConst.NS_PDFA_ID, PDFA_CONFORMANCE, PDFA_CONFORMANCE_B); } xmp.setProperty(XMPConst.NS_XMP, XMP_CREATE_DATE, ((PdfDate) info.get(PdfName.CREATIONDATE)).getW3CDate()); xmp.setProperty(XMPConst.NS_XMP, XMP_MODIFY_DATE, ((PdfDate) info.get(PdfName.MODDATE)).getW3CDate()); String title = extractInfo(PdfName.TITLE); if (title != null) { xmp.setLocalizedText(XMPConst.NS_DC, DublinCoreSchema.TITLE, //FIXME use the tag language? XMPConst.X_DEFAULT, XMPConst.X_DEFAULT, title); } String author = extractInfo(PdfName.AUTHOR); if (author != null) { //FIXME cache the options? PropertyOptions arrayOrdered = new PropertyOptions().setArrayOrdered(true); xmp.appendArrayItem(XMPConst.NS_DC, DublinCoreSchema.CREATOR, arrayOrdered, author, null); } String subject = extractInfo(PdfName.SUBJECT); if (subject != null) { PropertyOptions array = new PropertyOptions().setArray(true); xmp.appendArrayItem(XMPConst.NS_DC, DublinCoreSchema.SUBJECT, array, subject, null); xmp.setLocalizedText(XMPConst.NS_DC, DublinCoreSchema.DESCRIPTION, XMPConst.X_DEFAULT, XMPConst.X_DEFAULT, subject); } String keywords = extractInfo(PdfName.KEYWORDS); if (keywords != null) { xmp.setProperty(XMPConst.NS_PDF, PDF_KEYWORDS, keywords); } String creator = extractInfo(PdfName.CREATOR); if (creator != null) { xmp.setProperty(XMPConst.NS_XMP, XMP_CREATOR_TOOL, creator); } SerializeOptions options = new SerializeOptions(); options.setUseCanonicalFormat(true); ByteArrayOutputStream out = new ByteArrayOutputStream(4096); XMPMetaFactory.serialize(xmp, out, options); return out.toByteArray(); } catch (XMPException e) { throw new JRRuntimeException(e); } }