Bruno Lowagie (iText) wrote: > I think the second option would > even be possible with the current iText version (provided > you know how to work with iText at the lowest PDF level).
I added a method to PdfWriter that makes the first option possible during my lunch break. See source code and PDF in attachment. If you open the PDF in a text editor, you'll find three XMP streams. There's a reference to one of these streams in the page dictionary of each of the three pages. Now I only need the time to clean up my code and upload it to SVN. br, Bruno
xmp_test.pdf
Description: application/octetstream
package test;
import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.xml.xmp.DublinCoreSchema;
import com.lowagie.text.xml.xmp.PdfSchema;
import com.lowagie.text.xml.xmp.XmpArray;
import com.lowagie.text.xml.xmp.XmpSchema;
import com.lowagie.text.xml.xmp.XmpWriter;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
try {
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("xmp_test.pdf"));
document.open();
addPage(document, writer, 1);
addPage(document, writer, 2);
addPage(document, writer, 3);
document.close();
} catch (DocumentException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void addPage(Document document, PdfWriter writer, int page) throws IOException, DocumentException {
ByteArrayOutputStream os = new ByteArrayOutputStream();
XmpWriter xmp = new XmpWriter(os);
XmpSchema dc = new DublinCoreSchema();
XmpArray subject = new XmpArray(XmpArray.UNORDERED);
subject.add("Hello World; page " + page);
dc.setProperty(DublinCoreSchema.SUBJECT, subject);
xmp.addRdfDescription(dc);
PdfSchema pdf = new PdfSchema();
pdf.setProperty(PdfSchema.KEYWORDS, "Hello World, XMP, Metadata");
pdf.setProperty(PdfSchema.VERSION, "1.4");
xmp.addRdfDescription(pdf);
xmp.close();
writer.setPageXmpMetadata(os.toByteArray());
document.add(new Paragraph("Hello World, page " + page));
document.newPage();
}
}------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://itext.ugent.be/itext-in-action/
