use PdfSchema to update Meta data : Metadata « PDF « Java Tutorial






import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;

import com.lowagie.text.Document;
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 MainClass {
  public static void main(String[] args) throws Exception {
    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    XmpWriter xmp = new XmpWriter(os);
    XmpSchema dc = new DublinCoreSchema();
    XmpArray subject = new XmpArray(XmpArray.UNORDERED);
    subject.add("Metadata");
    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.setXmpMetadata(os.toByteArray());
    document.open();
    document.add(new Paragraph("Hello World"));
    document.close();
  }
}








29.32.Metadata
29.32.1.Read PDF to add some metadata
29.32.2.Get Pdf metadata
29.32.3.Add XMP metadata automatically, based on the PDF metadata
29.32.4.Get meta data from pdf document
29.32.5.Set meta data to pdf document
29.32.6.use PdfSchema to update Meta data