【问题标题】:The use of pageNum property in Acrobat Type Library 10.0 JSObject returns RunTime error 438在 Acrobat 类型库 10.0 JSObject 中使用 pageNum 属性返回 RunTime 错误 438
【发布时间】:2019-02-18 00:35:13
【问题描述】:

我需要获取页码才能从 .PDF 文档的特定页面中提取文本。我正在使用 Excel VBA 函数,该函数利用 Acrobat 类型库 10.0 中的 JSObject

这里是代码 sn-p,当我尝试从 Doc 对象引用 pageNum 属性时,代码会出现问题。我试图避开 AV 层并仅使用 PD 层,因此我的宏仅在后台运行并且不调用 Acrobat 应用程序。

Function getTextFromPDF_JS(ByVal strFilename As String) As String

   Dim pdDoc As New AcroPDDoc
   Dim pdfPage As Acrobat.AcroPDPage
   Dim pdfBookmark As Acrobat.AcroPDBookmark

   Dim jso As Object
   Dim BookMarkRoot As Object
   Dim vBookmark As Variant
   Dim objSelection As AcroPDTextSelect
   Dim objHighlight As AcroHiliteList
   Dim currPage As Integer
   Dim strText As String
   Dim BM_flag As Boolean
   Dim count As Integer
   Dim word As Variant


   strText = ""
   If (pdDoc.Open(strFilename)) Then


      Set jso = pdDoc.GetJSObject
      Set BookMarkRoot = jso.BookMarkRoot

      vBookmark = jso.BookMarkRoot.Children


    'Add a function call to see if a particular bookmark exists within the .PDF
    Set pdfBookmark = CreateObject("AcroExch.PDBookmark")

    BM_flag = pdfBookmark.GetByTitle(pdDoc, "Title Page")

If (BM_flag) Then

   For i = 0 To UBound(vBookmark)

        If vBookmark(i).Name = "Title Page" Then

            vBookmark(i).Execute
            jso.pageNum


         Set pdfPage = pdDoc.AcquirePage(pageNum)
         Set objHighlight = New AcroHiliteList
         objHighlight.Add 0, 10000 ' Adjust this up if it's not getting all the text on the page
         Set objSelection = pdfPage.CreatePageHilite(objHighlight)

         If Not objSelection Is Nothing Then
            For tCount = 0 To objSelection.GetNumText - 1
               strText = strText & objSelection.GetText(tCount)
            Next tCount
         End If

         Exit For
         End If
pdDoc.Close




End If


End If

   getTextFromPDF_JS = strText

End Function

【问题讨论】:

    标签: javascript excel vba acrobat-sdk


    【解决方案1】:

    jso.pageNum = 0;设置页码

    pageNo = jso.pageNum;获取页码

    编辑:3.3.19

    嗯,看来您必须使用 AVDoc 才能通过 jso.pageNum 获取当前的实际页面。此外,如果您使用 AVdoc,Acobat 窗口将隐藏在后台。示例:

    strFilename = "d:\Test2.pdf"
    set avDoc = CreateObject("AcroExch.AVDoc")
    If (avDoc.Open(strFilename,"")) Then
        Set pdDoc = avDoc.getPDDoc()
        Set jso = pdDoc.GetJSObject
        pageNo = jso.pageNum
        msgbox(pageNo)
    end if
    

    【讨论】:

    • 我无法在 VBA 中使用 pageNo = jso.pageNum 的语法访问页码,我收到错误 438。请更具体。
    猜你喜欢
    • 1970-01-01
    • 2015-08-04
    • 1970-01-01
    • 1970-01-01
    • 2019-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多