Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Adding Metadata Using Visual Basic 2008

Adding Metadata Using Visual Basic 2008

Scheduled Pinned Locked Moved Visual Basic
questionjavascriptdebugginghelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Harold_Wishes
    wrote on last edited by
    #1

    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.CAcroApp

    Private 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
    
    D 1 Reply Last reply
    0
    • H Harold_Wishes

      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.CAcroApp

      Private 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
      
      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups