Working with PDF File Metadata in C#
The following code snippet also work with Aspose.PDF.Drawing library.
In order to get file specific information of a PDF file, you first need to get the DocumentInfo object using Info property of the Document object. Once the DocumentInfo object is retrieved, you can get the values of the individual properties. The following code snippet shows you how to get PDF file information.
.NET Core 3.1
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void GetPDFFileInformation ()
{
// The path to the documents directory
var dataDir = RunExamples . GetDataDir_AsposePdf ();
// Open PDF document
using ( var document = new Aspose . Pdf . Document ( dataDir + "GetFileInfo.pdf" ))
{
// Get document information
var docInfo = document . Info ;
// Display document information
Console . WriteLine ( "Author: {0}" , docInfo . Author );
Console . WriteLine ( "Creation Date: {0}" , docInfo . CreationDate );
Console . WriteLine ( "Keywords: {0}" , docInfo . Keywords );
Console . WriteLine ( "Modify Date: {0}" , docInfo . ModDate );
Console . WriteLine ( "Subject: {0}" , docInfo . Subject );
Console . WriteLine ( "Title: {0}" , docInfo . Title );
}
}
.NET 8
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void GetPDFFileInformation ()
{
// The path to the documents directory
var dataDir = RunExamples . GetDataDir_AsposePdf ();
// Open PDF document
using ( var document = new Aspose . Pdf . Document ( dataDir + "GetFileInfo.pdf" ))
{
// Get document information
var docInfo = document . Info ;
// Display document information
Console . WriteLine ( "Author: {0}" , docInfo . Author );
Console . WriteLine ( "Creation Date: {0}" , docInfo . CreationDate );
Console . WriteLine ( "Keywords: {0}" , docInfo . Keywords );
Console . WriteLine ( "Modify Date: {0}" , docInfo . ModDate );
Console . WriteLine ( "Subject: {0}" , docInfo . Subject );
Console . WriteLine ( "Title: {0}" , docInfo . Title );
}
}
Aspose.PDF for .NET allows you to set file-specific information for a PDF, information like author, creation date, subject, and title. To set this information:
Create a DocumentInfo object.
Set the values of the properties.
Save the updated document using the Document class’ Save method.
The following code snippet shows you how to set PDF file information.
Aspose.PDF allows you to access a PDF file’s XMP metadata. To get a PDF file’s metadata:
Create a Document object and open the input PDF file.
Get the file’s metadata using the Metadata property.
The following code snippet shows you how to get metadata from the PDF file.
Aspose.PDF allows you to set metadata in a PDF file. To set metadata:
Create a Document object.
Set metadata values using the Metadata property.
Save the updated document using the Save method of the Document object.
The following code snippet shows you how to set metadata in a PDF file.
Some developers need to create a new metadata namespace with a prefix. The following code snippet shows how to insert metadata with prefix.