Skip to main content
Skip table of contents

Custom Metadata entry

Example written in answer to How to add / delete / retrieve information from a PDF using a custom property?

custommetaentry

JAVA

JAVA
/**
 * This example is written by Bruno Lowagie in answer to the following question:
 * http://stackoverflow.com/questions/26726485/itext-add-delete-retrieve-information-in-custom-property
 */
package sandbox.objects;

import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Header;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import sandbox.WrapToTest;

@WrapToTest
public class CustomMetaEntry {

    public static final String DEST = "results/objects/custom_meta.pdf";
    
    public static void main(String[] args) throws IOException,
            DocumentException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new CustomMetaEntry().createPdf(DEST);
    }
    
    public void createPdf(String dest) throws IOException, DocumentException {
        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(dest));
        document.addTitle("Some example");
        document.add(new Header("Test", "test"));
        document.open();
        Paragraph p = new Paragraph("Hello World");
        document.add(p);
        document.close();
    }
    
}

Results

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.