XmpWriter { public void close() throws IOException { if (outputStream == null) return; try { XMPMetaFactory.serialize(xmpMeta, outputStream, serializeOptions); outputStream = null; } catch (XMPException xmpExc) { throw new IOException(xmpExc.getMessage()); } } XmpWriter(OutputStream os, String utfEncoding, int extraSpace);  XmpWriter(OutputStream os);  XmpWriter(OutputStream os, PdfDictionary info);  XmpWriter(OutputStream os, Map<String, String> info); XMPMeta getXmpMeta(); void setReadOnly(); void setAbout(String about); @Deprecated void addRdfDescription(String xmlns, String content); @Deprecated void addRdfDescription(XmpSchema s); void setProperty(String schemaNS, String propName, Object value); void appendArrayItem(String schemaNS, String arrayName, String value); void appendOrderedArrayItem(String schemaNS, String arrayName, String value); void appendAlternateArrayItem(String schemaNS, String arrayName, String value); void serialize(OutputStream externalOutputStream); void close(); void addDocInfoProperty(Object key, String value); static final String UTF8; static final String UTF16; static final String UTF16BE; static final String UTF16LE; }
@Test public void createPdfAutomaticTest() throws IOException, DocumentException { String fileName = "xmp_metadata_automatic.pdf"; Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(OUT_FOLDER + fileName)); document.addTitle("Hello World example"); document.addSubject("This example shows how to add metadata & XMP"); document.addKeywords("Metadata, iText, step 3"); document.addCreator("My program using 'iText'"); document.addAuthor("Bruno Lowagie & Paulo Soares"); writer.createXmpMetadata(); document.open(); document.add(new Paragraph("Hello World")); document.close(); CompareTool ct = new CompareTool(); Assert.assertNull(ct.compareXmp(OUT_FOLDER + fileName, CMP_FOLDER + fileName, true)); }
@Test public void manipulatePdfTest() throws IOException, DocumentException { String fileName = "xmp_metadata_added.pdf"; PdfReader reader = new PdfReader(CMP_FOLDER + "pdf_metadata.pdf"); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(OUT_FOLDER + fileName)); HashMap<String, String> info = reader.getInfo(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); XmpWriter xmp = new XmpWriter(baos, info); xmp.close(); stamper.setXmpMetadata(baos.toByteArray()); stamper.close(); reader.close(); CompareTool ct = new CompareTool(); Assert.assertNull(ct.compareXmp(OUT_FOLDER + fileName, CMP_FOLDER + fileName, true)); }