This example shows how to insert document properties. Document properties can be viewed from Acrobat Reader and most commonly provide information on the document Title and Author.

This example requires some knowledge of the Adobe PDF Specification. Section 9.2.1 of the document details the way in which document properties are stored. Section 3.8.2 of the document details the way that dates are specified within PDF documents.




First we create an ABCpdf Doc object and add some simple content.

Doc theDoc = new Doc();
theDoc.Page = theDoc.AddPage();
theDoc.AddText("My first document...");

[Visual Basic]
Dim theDoc As Doc = New Doc()
theDoc.Page = theDoc.AddPage()
theDoc.AddText("My first document...")




Looking at the Adobe PDF Specification we can see that the document properties we want to change are referenced from an entry called "/Info" in the document trailer. So our first step is to create a new PDF dictionary and reference it from the this entry.

int theID = theDoc.AddObject("<< >>");
theDoc.SetInfo(-1, "/Info:Ref", theID.ToString());

[Visual Basic]
Dim theID As Integer = theDoc.AddObject("<< >>")
theDoc.SetInfo(-1, "/Info:Ref", theID.ToString())




Now we have to insert our summary information into the object we've just added.

theDoc.SetInfo(theID, "/Title:Text", "ABCpdf");
theDoc.SetInfo(theID, "/Author:Text", "WebSupergoo");
theDoc.SetInfo(theID, "/Subject:Text", "ABCpdf Documentation");
theDoc.SetInfo(theID, "/Keywords:Text", "ABCpdf,PDF,Docs");
theDoc.SetInfo(theID, "/Creator:Text", "WebSupergoo");
DateTime theDate = DateTime.Now;
theDoc.SetInfo(theID, "/CreationDate:Text", theDate);
theDoc.SetInfo(theID, "/ModDate:Text", theDate);
theDoc.SetInfo(theID, "/Trapped:Name", "False");

[Visual Basic]
theDoc.SetInfo(theID, "/Title:Text", "ABCpdf")
theDoc.SetInfo(theID, "/Author:Text", "WebSupergoo")
theDoc.SetInfo(theID, "/Subject:Text", "ABCpdf Documentation")
theDoc.SetInfo(theID, "/Keywords:Text", "ABCpdf,PDF,Docs")
theDoc.SetInfo(theID, "/Creator:Text", "WebSupergoo")
Dim theDate As DateTime = DateTime.Now
theDoc.SetInfo(theID, "/CreationDate:Text", theDate)
theDoc.SetInfo(theID, "/ModDate:Text", theDate)
theDoc.SetInfo(theID, "/Trapped:Name", "False")




Finally we save.

// finished

[Visual Basic]
' finished