How to read PDF properties using C# and VB.NET
Syncfusion Essential PDF is a .NET PDF library used to create, read, and edit PDF documents. Using this library, you can read the document information of an existing PDF like author, creation date, subject, title, and producer, using C# and VB.NET.
Steps to read PDF properties programmatically:
- Create a new C# console application project.
- Install the Syncfusion.Pdf.WinForms NuGet package as reference to your .NET Framework application from NuGet.org.
- Include the following namespaces in the Program.cs file.
C#
using Syncfusion.Pdf.Parsing; using System;
VB.NET
Imports Syncfusion.Pdf.Parsing Imports System
- Use the following code snippet to read PDF properties.
C#
//Load the PDF document PdfLoadedDocument loadedDocument = new PdfLoadedDocument("DocumentInformation.pdf"); //Read the PDF document information Console.WriteLine("Author: {0}", loadedDocument.DocumentInformation.Author); Console.WriteLine("Creation Date: {0}", loadedDocument.DocumentInformation.CreationDate); Console.WriteLine("Modification Date: {0}", loadedDocument.DocumentInformation.ModificationDate); Console.WriteLine("Creator: {0}", loadedDocument.DocumentInformation.Creator); Console.WriteLine("Keywords: {0}", loadedDocument.DocumentInformation.Keywords); Console.WriteLine("Subject: {0}", loadedDocument.DocumentInformation.Subject); Console.WriteLine("Title: {0}", loadedDocument.DocumentInformation.Title); Console.WriteLine("Producer: {0}", loadedDocument.DocumentInformation.Producer); //Close the loaded document loadedDocument.Close(true); Console.ReadLine();
VB.NET
'Load the PDF document Dim loadedDocument As New PdfLoadedDocument("DocumentInformation.pdf") 'Read the PDF document information Dim author As String = loadedDocument.DocumentInformation.Author Dim creationDate As DateTime = loadedDocument.DocumentInformation.CreationDate Dim creator As String = loadedDocument.DocumentInformation.Creator Dim keywords As String = loadedDocument.DocumentInformation.Keywords Dim subject As String = loadedDocument.DocumentInformation.Subject Dim title As String = loadedDocument.DocumentInformation.Title 'Close the document loadedDocument.Close(True)
A complete working sample can be downloaded from PDFPropertiesSample.zip.
By executing the program, you will get the console window as follows.
Take a moment to peruse the documentation, where you can find options like set PDF document information, read and modify the document properties of an existing PDF document and features like adding XMP metadata, adding custom schema and custom metadata to the PDF document, and removing custom metadata from PDF with code examples.
Refer here to explore the rich set of Syncfusion Essential PDF features.
Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to link to learn about generating and registering Syncfusion license key in your application to use the components without trail message.