Modifying PDF document properties

How can I modify the PDF document properties programmatically using .NET code?

I have purchased a number of eBooks in PDF format and unfortunately the publishers have not set the Title, Author and Subject properties. You can see this on a document by accessing the file Properties dialog and selecting the PDF tab. This is a real pain when attempting to use the PDF eBook on an eReader device.

I don't want to have to purchase a full PDF Writer product to do this so I'm hoping someone can point me to a simple free library that I can use to modify the properties programmatically.

If no .NET library is available I'd appreciate any other technique.

Answers


Here's a list of open-source PDF Libraries in C#

A couple of other libraries, that are not on that list: ByteScout-PDF iTextSharp


Thanks to both Mindaugas and Knobloch. Since you both pointed to iTextSharp I went for this and was able to solve my problem using iTextSharp and code similar to that shown below. One thing I noticed was that the resulting file was 115,143 bytes smaller, from a starting file of 3,639,172, so it looks like I'm either losing some information or this library is more efficient than the original product used to create the document.

The other interesting thing is that when reading about this library I kept seeing links to iText in Action which is published by the same publisher of the eBooks that I am having problems with:-)

        using System.Diagnostics;
        using iTextSharp.text.pdf;
        using System.IO;
        using System.Collections;

        PdfReader pdfReader = new PdfReader(filePath);
        using (FileStream fileStream = new FileStream(newFilePath, FileMode.Create, FileAccess.Write))
        {
            string title = pdfReader.Info["Title"] as string;
            Trace.WriteLine("Existing title: " + title);

            PdfStamper pdfStamper = new PdfStamper(pdfReader, fileStream);

            // The info property returns a copy of the internal HashTable
            Hashtable newInfo = pdfReader.Info;

            newInfo["Title"] = "New title";

            pdfStamper.MoreInfo = newInfo;

            pdfReader.Close();
            pdfStamper.Close();
        }

Need Your Help

Stored Procedures or Not?

php mysql optimization stored-procedures mysqli

I have a PHP script which meets heavy load. It is a backend script for my smartphone game. In this script I do multiple inserts and selects with MySQL.

How to write Powershell help for my cmdlets

powershell-v2.0

I've written my own Powershell cmdlets in c#. How can I add help test, so the I can get a more complete description when users use "Get-Help MYCMDLET"

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.