How to set custom properties for PDF file in C#

PDF Document Properties has summary information of the PDF document, including Description, Security, Fonts, Custom and Advance. We have already showed you how to set the description for PDF file by using Spire.PDF. Now starts from Spire.PDF v3.5.34, it supports to manipulate the custom properties for PDF. Spire.PDF provides a DocumentInformation class and we can set PDF customer properties through setting properties of DocumentInformation.SetCustomerDefined.

Here comes to the code snippet of how to set the custom properties for PDF file in C#. Firstly, view the blank custom properties for the PDF file:

How to set custom properties for PDF file in C#

Step 1: Create a new PDF document and load from the file.

PdfDocument doc = new PdfDocument();
doc.LoadFromFile("sample.pdf");

Step 2: Set the custom properties.

doc.DocumentInformation.SetCustomerDefined("Number", "123");
doc.DocumentInformation.SetCustomerDefined("Name", "Daisy");
doc.DocumentInformation.SetCustomerDefined("Company", "e-iceblue");

Step 3: Save the document to file and launch to preview it.

doc.SaveToFile("result.pdf");
System.Diagnostics.Process.Start("result.pdf");

Effective screenshot after set the custom properties for PDF file:

How to set custom properties for PDF file in C#

Full codes:

static void Main(string[] args)
{
    PdfDocument doc = new PdfDocument();
    doc.LoadFromFile("sample.pdf");

    doc.DocumentInformation.SetCustomerDefined("Number", "123");
    doc.DocumentInformation.SetCustomerDefined("Name", "Daisy");
    doc.DocumentInformation.SetCustomerDefined("Company", "e-iceblue");

    doc.SaveToFile("result.pdf");
    System.Diagnostics.Process.Start("result.pdf");
}