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的话, 好像比较麻烦. 没有时间进一步研究

  • 相关阅读:
    各类免费资料及书籍索引大全(珍藏版)
    转—如何写一篇好的技术博客
    如何写技术博客
    Spring + Spring MVC + Mybatis 框架整合
    Httpclient 4.5.2 请求http、https和proxy
    HttpClient4.5.2 连接池原理及注意事项
    php加密数字字符串,使用凯撒密码原理
    php 阿里云视频点播事件回调post获取不到参数
    Nginx代理后服务端使用remote_addr获取真实IP
    记录:mac的浏览器访问任何域名、网址都跳转到本地127.0.0.1或固定网址
  • 原文地址:https://www.cnblogs.com/onecrazystone/p/13861906.html
Copyright © 2011-2022 走看看