itextpdf-generationitext7pdfhtml

Setting application/creator metadata with iText7 and htmlpdf


I have been using iText (on .Net) for some time but have only recently started using htmlpdf instead of building the document manually.

In previous projects I used the following code to set the document metadata:

    document = new Document();
    m = new MemoryStream();
    writer = PdfWriter.GetInstance(document, m);
    
    document.AddTitle("Document Title");
    document.AddAuthor("Me");
    document.AddSubject("Document subject");
    document.AddCreator("My System");

This worked very well.

When I first started using pdfhtml I noticed that the page <title> was being used as the document title (perfectly sensible), however I started looking for a way to set the other metadata such as Author and Subject.

I started reading the iText pdfHTML whitepaper here. This provided the following instructions: screenshot of iText documentation

This did not work. However, I did notice that some <meta> tag values (such as viewport settings) were showing up in the 'custom properties' section of the PDF document properties.

Through a little trial and error I worked out how to set most of the PDF meta data using HTML tags like this (see screenshot below for result):

    <meta name="author" content="Me" />
    <meta name="description" content="Document Subject" />
    <meta name="keywords" content="Keyword" />
    <title>Document Title</title>

This is great, and much better than setting the values programmatically.

However, I have not been able to work out the equivalent of Document.AddCreator() / pdfMetaData.setCreator() which normally shows up in the PDF Document properties as 'Application'.

I have tried meta tags with name="creator" and name="application" but no luck.

Does anyone know how I can do this? Is all of this meta data setting documented anywhere? (apologies if it is, I have looked!)

Thanks.

screenshot of PDF properties


Solution

  • application-name is what you're looking for.

    <meta name="application-name" content="Application" />
    <meta name="author" content="Author" />
    <meta name="description" content="Subject" />
    <meta name="keywords" content="Keywords" />
    <title>Title</title>
    

    PDF metadata