PM > Install-Package XDoc.PDF

How to Start Tutorials Troubleshooting Main Operations Convert PDF Read PDF Edit PDF PDF Report Generator Work with PDF Modules PDF Document PDF Pages Text Image Graph & Path Annotation, Markup & Drawing Redaction Security Digital Signature Forms Watermark Bookmark Link File Attachment File Metadata Printing Work with Other SDKs Barcode read Barcode create OCR Twain

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#

  1. Download XDoc.PDF Metadata Editor C# library
  2. Install C# library to read, modify, edit PDF metadata
  3. Step by Step Tutorial












  • 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":


  1. Title: pdf file title
  2. Author: pdf document author name
  3. Subject: subject of this document
  4. Keywords: list of keywords
  5. Creator
  6. Producer: name of the pdf document producer application
  7. CreateDate: document created date
  8. 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.

  1. How to read PDF XMP data using C#
  2. How to process PDF XMP data using C#
  3. How to update XMP data to PDF fileusing C#
  4. 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.

  1. Get PDF XMP string data using PDFMetadataHandler.GetMatadata() method
  2. Create a XmlDocument object from the XMP string data
  3. Read XMP data information through XML node list
  4. 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.

  1. Read xmp byte array data from a xml file
  2. 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);
    }
}








Common Asked Questions

How do I see the metadata of a PDF?

If you are using Adobe Acrobat reader to open PDF file, you can view the PDF metadata through menu in toolbar File > Properties > Description Using C# PDF library, you can open PDF document and extract all metadata information in C# ASP.NET Core, MVC web applications.

What is PDF metadata used for?

PDF metadata includes the PDF document information, such as title of the PDF document, author, subject, keywords and copyright information. You can use the metadata to manage your contents by searching or filtering author, title keywords. Using RasterEdge XDoc.PDF C# library, you can easily read, view PDF document metadata, search and find the PDF documents by metadata searching in your ASP.NET web and Windows applications.

Can you extract metadata from a PDF?

You can use free desktop applications or online free tools to extract metadata information from your PDFs. If you need enable PDF metadata extraction feature in your own application, you can use C# PDF library to open, read, and extract PDF metadata in your C# projects.

Does PDF remove metadata?

The PDF document metadata will be updated every time you edit it. You can remove PDF metadata information using Acrobat pro. You can also build a simple desktop or web tool to remove PDF sensitive metadata information using RasterEdge C# PDF library.

Where is PDF metadata stored?

The PDF metadata information is stored inside PDF document. You can export the metadata to another file or remove it from PDF document using Acrobat or other PDF editor apps. Using C# PDF library, you can create, edit, remove, export PDF document metadata with few lines of C# codes.

Can you tell if PDF metadata has been changed?

PDF metadata will be updated every time you modified the PDF document. You can view the "Last Modified" information through menu in toolbar File > Properties > Description.

You can use RasterEdge C# PDF library to view and update the PDF document last modified time in your C# ASP.NET, MVC web applications.

What tool removes metadata from PDF?

Most of the common PDF editor support deleting metadata from PDF document, such as Acrobat Pro, Foxit, PDF24. You can also remove PDF metadata by building a simple Windows tool using C# PDF Reader library.

What is XMP in PDF?

How do I add XMP metadata to a PDF?

Adobe XMP (Extensible Metadata Platform) is the metadata standard used by Adobe for all metadata management. Using XDoc.PDF C# library, you can easily create, update, remove, export XMP data from a PDF document in your C# ASP.NET Core, web projects.

How to remove XMP metadata from PDF?

You can use Adobe Acrobat Pro to remove XMP metadata from your PDF documents. However it may fail to delete XMP metadata from PDF/A document. You need use XDoc.PDF C# library to permanently remove all embedded XMP from PDF document in your C# ASP.NET web apps.

Are XMP files necessary?

XMP is very important for other PDF apps to read the PDF document. Using RasterEdge C# PDF library, you can do search on metadata and find the PDF documents in the C#.NET web and desktop apps.