PDF document properties are metadata embedded within a file, including its title, author, subject, keywords, and producer name. Although this information does not appear directly on PDF pages, it is useful for document searches, archive management, and automated workflows. In C# projects, Free Spire.PDF for .NET provides a straightforward way to write and read these properties. This article explains both operations and highlights several implementation details.
Environment Setup
Free Spire.PDF for .NET is a standalone PDF processing library that runs without Adobe Acrobat or other third-party software. Install it in your project through NuGet:
Install-Package FreeSpire.PDF Note that the free edition limits PDF loading and creation to 10 pages; pages beyond this limit are truncated. For lightweight tasks such as setting and reading properties, you can verify the examples using files that stay within this limit.
Set PDF Document Properties
The DocumentInformation property of the PdfDocument class provides access to standard document properties. It returns a PdfDocumentInformation object whose fields—including Title, Author, Subject, Keywords, and Producer—are readable and writable string properties.
The following example demonstrates the complete process of loading an existing PDF, updating its properties, and saving it as a new file. The sample property values contain practical information related to project archiving:
using Spire.Pdf; namespace PdfPropertyDemo { class SetProperties { static void Main(string[] args) { PdfDocument pdf = new PdfDocument(); pdf.LoadFromFile("ProjectReport_Original.pdf"); pdf.DocumentInformation.Title = "Q2 2026 Project Summary Report"; pdf.DocumentInformation.Author = "Technical Documentation Team"; pdf.DocumentInformation.Subject = "Summary of Project Progress and Resource Usage"; pdf.DocumentInformation.Keywords = "Project Management, Quarterly Report, Progress Tracking"; pdf.DocumentInformation.Producer = "Internal Document Generation Tool"; pdf.SaveToFile("ProjectReport_Tagged.pdf"); pdf.Close(); } } } After execution, ProjectReport_Tagged.pdf retains the original document content and carries the updated property information. The Producer field typically identifies the application that generated the PDF, making it useful for tracing a file’s origin in automated workflows.
If a property does not exist in the original PDF, reading it may return null or an empty string. This does not affect writing: you can assign a value directly.
Read PDF Document Properties
Reading properties also relies on DocumentInformation. The following example loads the PDF whose properties were updated, extracts each field, and writes the results to a text file for verification or archiving:
using Spire.Pdf; using System.IO; using System.Text; namespace PdfPropertyDemo { class GetProperties { static void Main(string[] args) { PdfDocument pdf = new PdfDocument(); pdf.LoadFromFile("ProjectReport_Tagged.pdf"); StringBuilder content = new StringBuilder(); content.AppendLine("Title: " + pdf.DocumentInformation.Title); content.AppendLine("Author: " + pdf.DocumentInformation.Author); content.AppendLine("Subject: " + pdf.DocumentInformation.Subject); content.AppendLine("Keywords: " + pdf.DocumentInformation.Keywords); content.AppendLine("Producer: " + pdf.DocumentInformation.Producer); File.WriteAllText("ExtractedProperties.txt", content.ToString(), Encoding.UTF8); pdf.Close(); } } } This version uses AppendLine instead of explicit \r\n sequences and explicitly specifies UTF-8 encoding in File.WriteAllText. Specifying the encoding is particularly useful when property values contain Chinese or other non-ASCII characters: an encoding mismatch between the written file and the application reading it can produce garbled text. AppendLine also keeps the code concise while placing each field on a separate line.
Implementation Notes
As these examples show, Free Spire.PDF provides a direct interface for working with document properties. The property names largely correspond to entries in the PDF specification’s Info dictionary. Writing and reading use the same property accessors, with no need to parse the underlying structure separately.
Two details deserve attention in practical use. First, explicitly calling the PdfDocument object’s Close method after reading or writing helps release file handles promptly, especially when a subsequent operation needs immediate access to the same file. Second, properties that have not been set may return empty values. Before passing these values to downstream logic, such as conditional checks or database operations, it is sensible to check for null or empty values.
In addition to standard properties, PDFs can contain custom properties. These can be managed through the SetCustomProperty and GetCustomProperty methods and are useful for storing business information such as internal identifiers or version labels. Although custom properties are outside the scope of these examples, they can complement standard metadata in a document management system.
Conclusion
This article demonstrated the complete workflow for setting and reading PDF document properties in C# using Free Spire.PDF for .NET. To set properties, assign values directly to the string properties exposed by DocumentInformation. To read them, retrieve the corresponding values, collect them in a StringBuilder, and save the results to a text file.
The key implementation details are to specify the text encoding explicitly, close the document after processing, and handle potentially empty property values before using them in downstream operations. These small steps contribute to reliable behavior in real-world projects.

