How to Set and Edit PDF Metadata

by Jordi

Metadata in a PDF document refers to descriptive information about the document itself. Metadata in a PDF include information such as the document's title, author, subject, keywords, creation date, modification date, and more. Metadata allows for PDFs to be better indexed and searched in databases. It also increases their searchability on the internet.




C# NuGet Library for PDF

Install with NuGet

Install-Package IronPdf
or
Java PDF JAR

Download DLL

Download DLL

Manually install into your project

C# NuGet Library for PDF

Install with NuGet

Install-Package IronPdf
or
Java PDF JAR

Download DLL

Download DLL

Manually install into your project

Start using IronPDF in your project today with a free trial.

First Step:
green arrow pointer

Check out IronPDF on Nuget for quick installation and deployment. With over 8 million downloads, it's transforming PDF with C#.

C# NuGet Library for PDF nuget.org/packages/IronPdf/
Install-Package IronPdf

Consider installing the IronPDF DLL directly. Download and manually install it for your project or GAC form: IronPdf.zip

Manually install into your project

Download DLL

Set and Edit Metadata Example

When using IronPDF, setting and editing the generic metadata fields in PDFs is a straightforward process. You can easily access the MetaData property to modify the available metadata fields.

:path=/static-assets/pdf/content-code-examples/how-to/metadata-set-edit.cs
using IronPdf;
using System;

ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Metadata</h1>");

// Access the MetaData class and set the pre-defined metadata properties.
pdf.MetaData.Author = "Iron Software";
pdf.MetaData.CreationDate = DateTime.Today;
pdf.MetaData.Creator = "IronPDF";
pdf.MetaData.Keywords = "ironsoftware,ironpdf,pdf";
pdf.MetaData.ModifiedDate = DateTime.Now;
pdf.MetaData.Producer = "IronPDF";
pdf.MetaData.Subject = "Metadata Tutorial";
pdf.MetaData.Title = "IronPDF Metadata Tutorial";

pdf.SaveAs("pdf-with-metadata.pdf");
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#

Output PDF

To view the document metadata, click on the three vertical dots and access the Document properties.

Set and Retrieve Metadata Dictionary

The GetMetaDataDictionary method allows you to retrieve the existing metadata dictionary and access the metadata information stored within the document. The SetMetaDataDictionary method provides an effective way to rewrite the metadata dictionary. If a key is not present in the generic metadata fields, it will be considered a customer metadata property.

:path=/static-assets/pdf/content-code-examples/how-to/metadata-set-and-get-metadata-dictionary.cs
using IronPdf;
using System.Collections.Generic;

ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Metadata</h1>");

Dictionary<string, string> newMetadata = new Dictionary<string, string>();
newMetadata.Add("Title", "How to article");
newMetadata.Add("Author", "IronPDF");

// Set metadata dictionary
pdf.MetaData.SetMetaDataDictionary(newMetadata);

// Retreive metadata dictionary
Dictionary<string, string> metadataProperties = pdf.MetaData.GetMetaDataDictionary();
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#

Output PDF

To view the document metadata, click on the three vertical dots and access the Document properties.

Add, Edit, and Remove Custom Metadata Example

In addition to the standard metadata of a PDF document, you have the ability to include custom metadata properties. These custom properties are often not visible in PDF viewer software, as they typically only display the generic metadata and may not retrieve all existing metadata properties.

Add and Edit Custom Metadata

To add custom metadata simply access the CustomProperties property and invoke the Add method. Editing custom metadata requires passing the key value to the CustomProperties property and reassigning its value.

:path=/static-assets/pdf/content-code-examples/how-to/metadata-custom-properties.cs
using IronPdf;
using IronPdf.MetaData;

ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Metadata</h1>");

PdfCustomMetadataProperties customProperties = pdf.MetaData.CustomProperties;

// Add custom property
customProperties.Add("foo", "bar"); // Key: foo, Value: bar

// Edit custom property
customProperties["foo"] = "baz";
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#

Remove Custom Metadata

There are two ways to remove custom metadata from a PDF document. You can utilize the RemoveMetaDataKey method, accessible through the Metadata property, or use the Remove method from the CustomProperties property.

:path=/static-assets/pdf/content-code-examples/how-to/metadata-remove-custom-properties.cs
using IronPdf;

ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Metadata</h1>");

// Add custom property to be deleted
pdf.MetaData.CustomProperties.Add("willBeDeleted", "value");

// Remove custom property _ two ways
pdf.MetaData.RemoveMetaDataKey("willBeDeleted");
pdf.MetaData.CustomProperties.Remove("willBeDeleted");
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#