Skip to main content
Skip table of contents

Custom Metadata entry

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


custommetaentry

JAVA

JAVA
/*
    This file is part of the iText (R) project.
    Copyright (c) 1998-2023 Apryse Group NV
    Authors: Apryse Software.

    For more information, please contact iText Software at this address:
    sales@itextpdf.com
 */
package com.itextpdf.samples.sandbox.objects;

import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Paragraph;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

public class CustomMetaEntry {
    public static final String DEST = "./target/sandbox/objects/custom_meta_entry.pdf";

    public static void main(String[] args) throws IOException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new CustomMetaEntry().manipulatePdf(DEST);
    }

    protected void manipulatePdf(String dest) throws IOException {
        PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
        Document doc = new Document(pdfDoc);

        pdfDoc.getDocumentInfo().setTitle("Some example");

        // Add metadata to pdf document
        pdfDoc.getDocumentInfo().setMoreInfo("MetadataName", "metadataValue");

        Paragraph p = new Paragraph("Hello World");
        doc.add(p);

        doc.close();
    }
}

C#

C#
using System.IO;
using iText.Kernel.Pdf;
using iText.Layout;
using iText.Layout.Element;

namespace iText.Samples.Sandbox.Objects
{
    public class CustomMetaEntry
    {
        public static readonly string DEST = "results/sandbox/objects/custom_meta_entry.pdf";

        public static void Main(string[] args)
        {
            FileInfo file = new FileInfo(DEST);
            file.Directory.Create();
            new CustomMetaEntry().ManipulatePdf(DEST);
        }

        protected void ManipulatePdf(string dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
            Document doc = new Document(pdfDoc);

            pdfDoc.GetDocumentInfo().SetTitle("Some example");
            
            // Add metadata to pdf document
            pdfDoc.GetDocumentInfo().SetMoreInfo("MetadataName", "metadataValue");

            Paragraph p = new Paragraph("Hello World");
            doc.Add(p);

            doc.Close();
        }
    }
}

Results

JavaScript errors detected

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

If this problem persists, please contact our support.