C# tutorial: PDF metadata

PDF metadata

When creating a PDF document, you might want to make sure that people could find out information about the PDF document. You can accomplish this task by adding metadata to the PDF document. The code shown below adds the title, the subject, the author, and its keywords to the PDF document. Other information such as the file path, the producer, the date created, and the date modified of the document are added automatically by iTextSharp.

//create a document object
var doc = new Document();
//get the current directory
string path ="D:/";
//get PdfWriter object
PdfWriter.GetInstance(doc, new FileStream(path + "pdfdoc.pdf", FileMode.Create));
//open the document for writing
//write a paragraph to the document
doc.Add(new Paragraph("Meta data added to this document"));
doc.AddTitle("Creating a PDF");
doc.AddSubject("This example shows you how to add meta data to your PDF file.");
doc.AddAuthor("Yuk Dara");
doc.AddKeywords("PDF, iTextSharp");
//close the document
//view the result pdf file
System.Diagnostics.Process.Start(path + "pdfdoc.pdf");

pdf add metadata

The metdata of the PDF document is stored in the info dictionary. You can read the metadata of the document by using the Info property of the PdfReader object. This property returns a collection of pairs of key and values.

pdf read metadata

PdfReader reader = new PdfReader("D:/pdfdoc.pdf");
IDictionary<String, String> metadic = reader.Info;
var dic = from m in metadic
select m;
foreach(var d in dic){
Console.WriteLine(d.Key+": "+d.Value);

iTextSharp also allows you to modify the metadata of the PDF document. It is easy. You need to store pairs of key and value in a SortedDictionary or SortedList data structure. Then add the data structure to the PdfStamper object by using its MoreInfo property.

PdfReader reader = new PdfReader("D:/pdfdoc.pdf");
PdfStamper stamper = new PdfStamper(reader, new FileStream("d:/metainfo.pdf",FileMode.Create));
SortedDictionary<String,String> inf=new SortedDictionary<String, String>();
inf.Add("Title", "Modifying metadata");
inf.Add("Subject","This example shows you how to modify metadata.");
inf.Add("Author","Also Yuk Dara");
inf.Add("Keywords","PDF, iTextSharp, Metadata, Good");
stamper.MoreInfo = inf;

pdf modify metadata


lorretadt comment


The first and easiest way to kown vb.net acrobat pdf additional metadata is to use the rasteredage page http://www.rasteredge.com/how-to/vb-net-imaging/pdf-document-metadata/

lorretadt comment


You can download and try this interesting high quality software on rasteredge page for c# acrobat pdf additional metadata on http://www.rasteredge.com/how-to/csharp-imaging/pdf-document-metadata/


This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.