These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Adding custom document properties

cl5792
Registered: Jul 17 2008
Posts: 53
Answered

Is there a way to add a custom document property via VB or Javascript? The only way I can see is to go to the "Document Properties" and "Custom" tab to manually add new properties. I would like to add a new property to an existing PDF with VB code.

thanks,

My Product Information:
Acrobat Pro 9.3.1, Windows
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
Have you looked at the 'info' property of the 'doc' object in the Acrobat JS API Reference. Look closely at example 2.

George Kaiser

cl5792
Registered: Jul 17 2008
Posts: 53
Thank you for the response (and so quick too). The example you referenced is helpful to extract the value of the property. But I was needing to add a custom property to the document. Any help with that - what method to use?
UVSAR
Expert
Registered: Oct 29 2008
Posts: 1357
Look at the doc.metadata property, which gives you direct access into the XMP stack Adding entries takes a bit of code as you need to build the XML manually, but it's easy enough once you've got the function laid out. The custom properties entries from the UI tab appear in the pdfx: namespace, but the quickest way to find where a property needs to be put in is to add it manually to a PDF and run a report on the stack, by running this in the console:

var r = new Report();
r.writeText(this.metadata);
r.open("MetadataReportFile");
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
Actually that example add the "ISBN" and 'PublishDate" custom data.
console.println("Before:");console.println(i + ": "+ this.info[i]);console.println("\n\nAfter:");this.info.Title = "JavaScript, The Definitive Guide";this.info.ISBN = "1-56592-234-4";this.info.PublishDate = new Date();for (var i in this.info)console.println(i + ": "+ this.info[i]);

The result when run from the JavaScript console:


Quote:
Before:
email:


After:
ContactEmail:
Authors: Adobe Developer Support
CreationDate: Wed Oct 18 2006 02:03:28 GMT-0500 (Central Daylight Time)
Subject: Adobe Acrobat 8.0 SDK
Author: Adobe Developer Support
Creator: FrameMaker 7.2
Producer: Acrobat Distiller 7.0.5 (Windows)
PublishDate: Wed May 19 2010 16:31:44 GMT-0500 (Central Daylight Time)
ModDate: Wed Dec 09 2009 11:35:16 GMT-0600 (Central Standard Time)
ISBN: 1-56592-234-4
Title: JavaScript, The Definitive Guide

true
And if you look at the Properties 'Custom' tab, you will see the 'ISBN' and 'PublishDate' fields have been added with values.

George Kaiser

cl5792
Registered: Jul 17 2008
Posts: 53
Thank so much for the assitance. I have created a function that adds the custom document property. The simplifed code is below:

Function SetPDFDocProperty(sFileName As String, sPropName As String, sPropValue As String) As Boolean

Dim oPDFDoc As New Acrobat.AcroAVDoc
Dim oPDDoc As New Acrobat.AcroPDDoc
Dim sPropField As String
Dim bSuccess As Boolean

SetPDFDocProperty = False
Set oPDFDoc = New Acrobat.AcroAVDoc
oPDFDoc.Open sFileName, "Temp"
Set oPDDoc = oPDFDoc.GetPDDoc()
bSuccess = oPDDoc.SetInfo(sPropField, sPropValue)
If bSuccess Then
bSuccess = oPDDoc.Save(33, sFileName) '... 33 = PDSaveFull (1) OR PDSaveCollectGarbage (32)
End If

oPDDoc.Close
oPDFDoc.Close (True)
Set oPDDoc = Nothing
Set oPDFDoc = Nothing

If bSuccess = True Then
SetPDFDocProperty = True
Else
SetPDFDocProperty = True
End If

Exit Function

This is working great.
Just because I am curious, is there a method to get the ID (not text) for a custom property (enumerate through the items) by the name and delete one?

Again, thanks for the replies and pointing me in the right direction.

Cammy
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
Using the 'info' property of the 'doc' object, I do not think so, but if you want to process the 'meta data' property contents then you probably could. The format the 'meta data' is an XMP file and is more complex than creating a name and setting a value. There is an example in the Acrobat JS API Reference, but that example only shows setting a copyright and copyright status and indicates there is significant coding in working with this data.

George Kaiser