Adding Metadata Using Visual Basic 2008
-
Hello, I have attached a VB program done in VB 2008 which adds annotations to an Acrobat PDF file specified by the user. So far, it works like a champ. However, my ultimate goal is to build a VB 2008 application that inserts metadata into the "Title", "Author", "Subject" and "Keywords" fields that are accessible from the Description tab of the Document Properties dialog box on the Acrobat "File" menu. I can do this in Acrobat's built-in JavaScript debugger just fine. For instance, the following will insert Harry Wishes into the author field.
this.info.author = "Harry Wishes"
My question: How do I invoke the Javascript object from Visual Basic 2008 that could access and modify this PDF metadata from Visual Basic? Help Apprectiated. Thanks! :)
Public Class Form1
Dim gApp As Acrobat.CAcroAppPrivate Sub Form1\_Load() gApp = CreateObject("AcroExch.App") End Sub Private Sub Button1\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim pdDoc As Acrobat.CAcroPDDoc Dim page As Acrobat.CAcroPDPage Dim jso As Object Dim path As String Dim point(1) As Integer Dim popupRect(3) As Integer Dim pageRect As Object Dim annot As Object Dim props As Object OpenFileDialog1.ShowDialog() path = OpenFileDialog1.FileName pdDoc = CreateObject("AcroExch.PDDoc") If pdDoc.Open(path) Then jso = pdDoc.GetJSObject If Not jso Is Nothing Then ' Get size for page 0 and setup arrays page = pdDoc.AcquirePage(0) pageRect = page.GetSize point(0) = 0 point(1) = pageRect.y popupRect(0) = 0 popupRect(1) = pageRect.y - 100 popupRect(2) = 200 popupRect(3) = pageRect.y ' Create a new text annot annot = jso.AddAnnot props = annot.getProps props.Type = "Text" annot.setProps(props) ' Fill in a few fields props = annot.getProps props.page = 1 props.point = point props.popupRect = popupRect props.author = "Rob McAfee" props.noteIcon = "Comment" props.strokeColor = jso.Color.red pro
-
Hello, I have attached a VB program done in VB 2008 which adds annotations to an Acrobat PDF file specified by the user. So far, it works like a champ. However, my ultimate goal is to build a VB 2008 application that inserts metadata into the "Title", "Author", "Subject" and "Keywords" fields that are accessible from the Description tab of the Document Properties dialog box on the Acrobat "File" menu. I can do this in Acrobat's built-in JavaScript debugger just fine. For instance, the following will insert Harry Wishes into the author field.
this.info.author = "Harry Wishes"
My question: How do I invoke the Javascript object from Visual Basic 2008 that could access and modify this PDF metadata from Visual Basic? Help Apprectiated. Thanks! :)
Public Class Form1
Dim gApp As Acrobat.CAcroAppPrivate Sub Form1\_Load() gApp = CreateObject("AcroExch.App") End Sub Private Sub Button1\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim pdDoc As Acrobat.CAcroPDDoc Dim page As Acrobat.CAcroPDPage Dim jso As Object Dim path As String Dim point(1) As Integer Dim popupRect(3) As Integer Dim pageRect As Object Dim annot As Object Dim props As Object OpenFileDialog1.ShowDialog() path = OpenFileDialog1.FileName pdDoc = CreateObject("AcroExch.PDDoc") If pdDoc.Open(path) Then jso = pdDoc.GetJSObject If Not jso Is Nothing Then ' Get size for page 0 and setup arrays page = pdDoc.AcquirePage(0) pageRect = page.GetSize point(0) = 0 point(1) = pageRect.y popupRect(0) = 0 popupRect(1) = pageRect.y - 100 popupRect(2) = 200 popupRect(3) = pageRect.y ' Create a new text annot annot = jso.AddAnnot props = annot.getProps props.Type = "Text" annot.setProps(props) ' Fill in a few fields props = annot.getProps props.page = 1 props.point = point props.popupRect = popupRect props.author = "Rob McAfee" props.noteIcon = "Comment" props.strokeColor = jso.Color.red pro
That's going to be a function of the PDF Library you're using, if it's exposed at all. Without the documentation on that library, your next bet is to use the Object Browser window (F2 in Visual Studio) to explore the libraries object model, looking for some methods and/or properties that might do this for you.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008