C# PDF Metadata Editor Library
How to read, edit, remove PDF metadata (title, keywords), XMP in c# ASP.NET web app
Allow C# Developers to Read, Add, Edit, Modify and Delete PDF Metadata in .NET Project
In this tutorial, you learn how to read, view, edit, modify PDF document metadata information in the C# ASP.NET Web, Windows applications.
- Support PDF document metadata
- Support PDF XMP (Extensible Metadata Platform)
- No Acrobat software installed. Not using 3rd party software.
How to read, view, modify, edit, remove PDF metadata information using C#
- Professional PDF SDK for adobe PDF document metadata editing in C# .NET framework
- Support .NET WinForms, ASP.NET MVC in IIS, ASP.NET Ajax, Azure cloud service, DNN (DotNetNuke), SharePoint
- Evaluation library and components provide varieties of functionalities to edit and update PDF metadata in .NET WinForms and ASP.NET
- C# source code for retrieving and updating PDF metadata in Visual Studio .NET console application
- Read and view PDF metadata in ASPX webpage without any adobe viewer components
- Add metadata to PDF document in C# .NET framework program
- Remove and delete metadata from PDF file
- Also a PDF metadata extraction control
- Batch processing PDF metadata in C#.NET class
PDF document processor SDK from RasterEdge is a professional PDF component package that covers all the aspects of PDF document manipulations in .NET Framework application, like creating, viewing, saving, editing, annotating and handling.
The term metadata can be literally interpreted as "data about data". In PDF document imaging applications, metadata can be used as a useful method to provide additional information about the PDF document, such as the information about PDF document author, PDF publication date and copyright restrictions.
RasterEdge XDoc.PDF SDK for .NET supplies optimized standards-based PDF document metadata processing technologies. C#.NET developers can easily integrate this PDF document metadata manipulating control into their professional PDF document content management system, which can not only allow developers and end-users to edit PDF document metadata but also permit them to have an extensive search for encoded metadata based on certain parameters.
About PDF Document Metadata
PDF document Metadata includes information about the document and its contents, such as the author's name, keywords, and copyright information,
that can be used by search utilities.
In XDoc.PDF SDK, you can store, read, and update PDF metadata information through class "PDFMetadata".
List of PDF metadata data in class "PDFMetadata":
- Title: pdf file title
- Author: pdf document author name
- Subject: subject of this document
- Keywords: list of keywords
- Creator
- Producer: name of the pdf document producer application
- CreateDate: document created date
- ModifiedDate: document last modified date
About PDF Extensible Metadata Platform (XMP)
The Extensible Metadata Platform (XMP) is an ISO standard, originally created by Adobe Systems Inc.,
for the creation, processing and interchange of standardized and custom metadata for digital documents and data sets.
The defined XMP data model can be used to store any set of metadata properties. These can be simple name/value pairs, structured values or lists of values. The data can be nested as well.
XDoc.PDF SDK has provided API for developers to read, update, remove the XMP data.
- How to read PDF XMP data using C#
- How to process PDF XMP data using C#
- How to update XMP data to PDF fileusing C#
- How to remove PDF XMP data using C#
C#: Read, view PDF document metadata information
You can read, retrieve the PDF metadata from an existing PDF file through PDFDocument.
You get a PDFMetadata object from PDFDocument, and PDFMetadata object contains all the PDF metadata information.
#region read PDF document metadata information
internal static void readPdfMetadata()
{
// Retrieve PDF document metadata.
String inputFilePath = @"C:\demo.pdf";
PDFDocument doc = new PDFDocument(inputFilePath);
PDFMetadata metadata = doc.GetDescription();
Console.WriteLine("Title: " + metadata.Title);
Console.WriteLine("Author: " + metadata.Author);
Console.WriteLine("Subject: " + metadata.Subject);
Console.WriteLine("Keywords: " + metadata.Keywords);
Console.WriteLine("Creator: " + metadata.Creator);
Console.WriteLine("Producer: " + metadata.Producer);
Console.WriteLine("Create Date: " + metadata.CreatedDate.ToString());
Console.WriteLine("Modified Date: " + metadata.ModifiedDate.ToString());
}
#endregion
C#: Modify, edit PDF metadata information
The following C# example code explains how to modify, change existing PDF metadata, such as keywords, producer, document title in C# code.
#region update PDF document metadata information
internal static void updatePdfMetadata()
{
// Update PDF document metadata.
PDFMetadata metadata = new PDFMetadata();
metadata.Title = "Title";
metadata.Author = "Qi";
metadata.Subject = "None";
metadata.Keywords = "University, Public, etc.";
metadata.Creator = "MS Office Word";
metadata.Producer = "RE";
metadata.CreatedDate = new DateTime(2014, 11, 21, 10, 45, 12);
metadata.ModifiedDate = new DateTime(2015, 11, 21, 10, 45, 12);
String inputFilePath = @"C:\demo.pdf";
String outputFilePath = @"C:\output.pdf";
PDFDocument doc = new PDFDocument(inputFilePath);
doc.SetDescription(metadata);
doc.Save(outputFilePath);
}
#endregion
C#: Remove, delete PDF document metadata information
The following C# example code explains how to remove, clear all existing PDF document metadata.
#region delete PDF document metadata information
internal static void deletePdfMetadata()
{
// Set PDF document metadata with default value.
PDFMetadata metadata = new PDFMetadata();
metadata.Title = "";
metadata.Author = "";
metadata.Subject = "";
metadata.Keywords = "";
metadata.Creator = "";
metadata.Producer = "";
metadata.CreatedDate = new DateTime(2014, 11, 21, 10, 45, 12);
metadata.ModifiedDate = new DateTime(2015, 11, 21, 10, 45, 12);
String inputFilePath = @"C:\demo.pdf";
String outputFilePath = @"C:\output.pdf";
PDFDocument doc = new PDFDocument(inputFilePath);
doc.SetDescription(metadata);
doc.Save(outputFilePath);
}
#endregion
C#: Read, view PDF XMP advanced metadata information
The following C# example code explains how to read XMP metadata in String from PDF file in C# code:
String inputFilePath = "C:\\1.pdf";
// Get document's metadata content in String format.
String xmpDataBytes = PDFMetadataHandler.GetMatadata(inputFilePath);
if (!String.IsNullOrEmpty(xmpDataBytes))
Console.WriteLine(xmpDataBytes);
else
Console.WriteLine("No document metadata in the file.");
Read XMP metadata from PDF Stream object in C# code:
using (FileStream inStream = File.Open("C:\\1.pdf", FileMode.Open, FileAccess.Read, FileShare.Read))
{
// Get document's metadata content in String format.
String xmpDataBytes = PDFMetadataHandler.GetMatadata(inStream);
// …
}
C#: Process PDF XMP advanced metadata information
Below are the steps and C# example source code to read PDF XMP metadata in XML document.
- Get PDF XMP string data using PDFMetadataHandler.GetMatadata() method
- Create a XmlDocument object from the XMP string data
- Read XMP data information through XML node list
- Save XMP xml data into an xml file
String inputFilePath = "C:\\1.pdf";
// Get document's metadata content in String format.
String xmpDataBytes = PDFMetadataHandler.GetMatadata(inputFilePath);
// Load metadata content to a XmlDocument object.
System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
xmlDoc.LoadXml(xmpDataBytes);
// Retreive an exist tag <pdf:Producer>
System.Xml.XmlNodeList nodes = xmlDoc.GetElementsByTagName("pdf:Producer");
foreach (System.Xml.XmlNode node in nodes)
Console.WriteLine("{0}: ‘{1}’", node.Name, node.InnerText);
// …
Edit the advanced metadata in C# code:
String inputFilePath = "C:\\1.pdf";
// Get document's metadata content in String format.
String xmpDataBytes = PDFMetadataHandler.GetMatadata(inputFilePath);
// Load metadata content to a XmlDocument object.
System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
xmlDoc.LoadXml(xmpDataBytes);
// Edit exist tag <pdf:Producer>, change inner text to "Generated by Raster Edge"
System.Xml.XmlNodeList nodes = xmlDoc.GetElementsByTagName("pdf:Producer");
foreach (System.Xml.XmlNode node in nodes)
node.InnerText = "Generated by Raster Edge";
// Save the modified metadata content to a file.
xmlDoc.Save("C:\\metadata.xml");
C#: Update PDF XMP advanced metadata information
Below are the steps and C# example source code to update PDF XMP metadata.
- Read xmp byte array data from a xml file
- Use PDFMetadataHandler.SetMetadata() method to save XMP data into PDF file.
String inputFilePath = "C:\\1.pdf";
String outputFilePath = "C:\\output.pdf";
// Load metdata content from a XML file.
byte[] xmpDataBytes = File.ReadAllBytes("C:\\metadata.xml");
// Update document metadata content.
String xmpData = Encoding.UTF8.GetString(xmpDataBytes);
PDFMetadataHandler.SetMetadata(inputFilePath, outputFilePath, xmpData);
Update XMP metadata from PDF Stream object in C# code:
// Load metdata content from a XML file.
byte[] xmpDataBytes = File.ReadAllBytes("C:\\metadata.xml");
using (FileStream inStream = File.Open("C:\\1.pdf", FileMode.Open, FileAccess.Read, FileShare.Read))
{
using (FileStream oStream = File.Open("C:\\output.pdf", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite))
{
// Update document metadata content.
String xmpData = Encoding.UTF8.GetString(xmpDataBytes);
PDFMetadataHandler.SetMetadata(inStream, oStream, xmpData);
}
}
C#: Remove PDF XMP advanced metadata information
Call method PDFMetadataHandler.RemoveMetadata() to remove XMP metadata from an existing PDF file, and save to a new PDF file in C# code:
String inputFilePath = "C:\\1.pdf";
String outputFilePath = "C:\\output.pdf";
// Remove document metadata content in the source file.
PDFMetadataHandler.RemoveMetadata(inputFilePath, outputFilePath);
Remove XMP metadata from PDF Stream object in C# code:
using (FileStream inStream = File.Open("C:\\1.pdf", FileMode.Open, FileAccess.Read, FileShare.Read))
{
using (FileStream oStream = File.Open("C:\\output.pdf", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite))
{
// Remove document metadata content in the source file.
PDFMetadataHandler.RemoveMetadata(inStream, oStream);
}
}