zoukankan      html  css  js  c++  java
  • VB.Net VBA 访问 Acrobat,浏览所有 annotation. 代码执行通过.

    下面是VBA中的代码

    '//mr:: 调用acrobat的方法, 大小写都可以.
    '//mr:: 不需要AcroExch.App这个对象.
    Sub GetAnnotationFromPDF()
    
    Dim AcrApp As Acrobat.AcroApp
    
    Dim AcrAvDoc As Acrobat.AcroAVDoc
    
    Dim pdDoc As Acrobat.CAcroPDDoc
    
    Dim Jso As Object
    
    Dim Annots() As Variant
    
    Dim Annot As Variant
    
    Dim Props As Object
    
    Dim strContent, strSubType, strAuthor, strSubject As String
    
    'Set AcrApp = New Acrobat.AcroApp
    'Set AcrApp = CreateObject("AcroExch.App")
    'Set AcrAvDoc = AcrApp.GetActiveDo
    
    Set pdDoc = CreateObject("AcroExch.PDDoc")
    
    pdDoc.Open ("C:UsersOneCrazyStoneDesktopH12_hdevelop_users_guide_JOM.pdf")
    
    'Set pdDoc = AcrAvDoc.GetPDDoc
    
    Set Jso = pdDoc.GetJSObject
    
    Jso.syncAnnotScan  '//mr?? 这句还不能少
    
    Annots = Jso.getAnnots()
    
    Dim i As Integer
    i = 0
    
    
    For Each Annot In Annots
    
        Set Props = Annot.getprops
    
        strAuthor = Props.Author
    
        strSubject = Props.Subject
    
        strContent = Props.contents
    
        strSubType = Props.Type
        
        Debug.Print str(i) + " " + strAuthor + " " + strSubType + " " + strContent
        
    Next
    
    Set Props = Nothing
    
    Set Annot = Nothing
    
    'Set Annots = Nothing
    Erase Annots
    
    Set Jso = Nothing
    
    Set pdDoc = Nothing
    
    Set AcrAvDoc = Nothing
    
    

    下面是VB.Net中的代码

    Public Sub Main()
            'Dim SOURCE_DOCUMENT As String = System.Windows.Forms.Application.StartupPath + "........TestFilesFormSample.pdf"
            'C:UsersOneCrazyStoneDesktopH12_hdevelop_users_guide_JOM.pdf
            Dim SOURCE_DOCUMENT As String = "C:UsersOneCrazyStoneDesktopH12_hdevelop_users_guide_JOM.pdf"
    
            Dim DATA_FILE As String = System.Windows.Forms.Application.StartupPath + "........TestFilesdata.txt"
    
            ' create at root level of sample
            Dim OUTPUT_FOLDER As String = System.Windows.Forms.Application.StartupPath + "/../../outputfolder/"
            System.IO.Directory.CreateDirectory(OUTPUT_FOLDER)
            Dim outputString As String
            Dim i As Short
    
            ' We gain access to the JavaScript DOM through the GetJSObject method
            ' of the CAcroPDDoc object.
    
            On Error GoTo ErrorHandler
    
            Dim retVal As Integer
            Dim count As Integer
            Dim srcDoc As Acrobat.CAcroPDDoc
            Dim srcApp As Acrobat.CAcroApp
    
            ' Open the source PDF document
            'srcApp = CreateObject("AcroExch.App")
            srcDoc = CreateObject("AcroExch.PDDoc")
            retVal = srcDoc.Open(SOURCE_DOCUMENT)
    
    
            If retVal <> -1 Then
                Err.Description = "Failed to open source document. Make sure that SOURCE_DOCUMENT has been configured."
                GoTo ErrorHandler
            End If
    
            ' Acquire the JSObject interface
    
            jsObj = srcDoc.GetJSObject
            jsObj.syncAnnotScan()
    
    
            Dim newDoc As Object
            Dim template As Object
            Dim existAnnotations() As Object
            Dim annots As Object
            Dim props As Object
    
            Dim aa As Object
    
            existAnnotations = jsObj.getannots()
    
            For Each aa In existAnnotations
                props = aa.getProps
                Debug.Print(props.Author + props.Contents)
            Next
          
    EndSub:
            System.Runtime.InteropServices.Marshal.ReleaseComObject(jsObj)
            jsObj = Nothing
            If Not srcDoc Is Nothing Then
                srcDoc.Close()
                System.Runtime.InteropServices.Marshal.ReleaseComObject(srcDoc)
                srcDoc = Nothing
            End If
            Exit Sub
    
    ErrorHandler:
    
            MsgBox("Error Occured: " & Err.Description)
            Resume EndSub
    
    End Sub
    

    在C#中调用Acrobat类型库, 如果也使用GetJSObject的话, 好像比较麻烦. 没有时间进一步研究

  • 相关阅读:
    设置MySQL的字符编码
    数据库面试题
    java.lang.IncompatibleClassChangeError: Implementing class
    下载SpringJar包
    使用命令wsimport构建WebService客户端
    java读取.properties配置文件的几种方法
    ELK5.X使用X-Pack配置密码
    Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'
    MySQL常用命令
    XPath常用定位节点元素语句总结
  • 原文地址:https://www.cnblogs.com/onecrazystone/p/13861906.html
Copyright © 2011-2022 走看看