Adds a native PDF object to the document.




int AddObject(string text)

[Visual Basic]
Function AddObject(text As String) As Integer



Name Description
text The raw native object to be added.
return The Object ID of the newly added Object.




You will not normally need to use this feature. However it can be useful if you wish to add objects which are defined in the PDF specification but not supported by ABCpdf .NET.

Be aware that the text you pass this function must be in native PDF format. This means that unusual characters in text strings must be appropriately escaped. For full details of the way that PDF objects are represented you should see the Adobe PDF Specification.

Your newly added object needs to be referenced from somewhere in the PDF document. If you do not reference your object it will be orphaned and will be deleted when the document is saved.




The following code adds a document information section to an existing PDF document. First it adds an empty dictionary and references it from the document trailer. Then it adds an Author, Title and Subject before saving.

There are multiple places that metadata can be put into a PDF. The most commonly used are the Info entry of the Trailer and the Metadata entry of the Catalog. The Info entry is the older and most widely recognized location. The Metadata entry is a more recent XML based store. It is important that information within these stores is consistent. If the information is inconsistent then you'll find that the metadata reported by different applications is different. To ensure that the data is consistent we're going to delete any XML Metadata entry that may be present. That way we force applications to report the Info store. However it wouldn't be a difficult matter to load up any XML in the Metadata entry and modify that as well as the Info entry.

Doc theDoc = new Doc();
if (theDoc.GetInfo(-1, "/Info") == "")
  theDoc.SetInfo(-1, "/Info:Ref", theDoc.AddObject("<< >>").ToString());
theDoc.SetInfo(-1, "/Info*/Author:Text", "Arthur Dent");
theDoc.SetInfo(-1, "/Info*/Title:Text", "Musings on Life");
theDoc.SetInfo(-1, "/Info*/Subject:Text", "Philosophy");
theDoc.SetInfo(theDoc.Root, "/Metadata:Del", "");

[Visual Basic]
Dim theDoc As Doc = New Doc()
If theDoc.GetInfo(- 1, "/Info") = "" Then
  theDoc.SetInfo(- 1, "/Info:Ref", theDoc.AddObject("<< >>").ToString())
End If
theDoc.SetInfo(- 1, "/Info*/Author:Text", "Arthur Dent")
theDoc.SetInfo(- 1, "/Info*/Title:Text", "Musings on Life")
theDoc.SetInfo(- 1, "/Info*/Subject:Text", "Philosophy")
theDoc.SetInfo(theDoc.Root, "/Metadata:Del", "")