如何使用 vb 获取 pdf 上下文?

How can I use vb to get pdf context?

我有一个函数可以获取 pdf 文件的页码。

Public Function GetNumPages(ByVal PdfFile As String) As Long  
    Dim objTempDoc As Object  
    Dim fso As FileSystemObject  
    Set fso = New FileSystemObject  

    If fso.FileExists(PdfFile ) Then  
        Set objTemp = CreateObject("AcroExch.PDDoc")  
        objTemp.Open pstrPdfFilename  
        GetNumPages = objTemp.GetNumPages  
        objTemp.Close  
        Set objTemp = Nothing  
    End If  

    Set fso = Nothing  
End Function  

我想获取 pdf 文件最后一页中最后一行的上下文。

我找到了这个 API,但我不知道如何使用它。 它会 return 我想要的上下文吗?

PDOCContext PDDocGetOCContext(PDDoc pdDoc)

我试过这种方式来使用API,但是失败了。

Set objTempDoc = CreateObject("AcroExch.PDDoc")
objTempDoc.Open PdfFile
myPDFPage = objTempDoc.GetOCContext

可以调用此函数获取最后一页的文本。

Public Function GetPDFText(ByVal pstrPdfFilename As String) As String

        Dim PDDoc As Object
        Dim CAcroRect As New Acrobat.AcroRect
        Dim PDPage As Acrobat.AcroPDPage
        Dim PDTxtSelect As Acrobat.AcroPDTextSelect
        Dim CArcoPoint As Acrobat.AcroPoint
        Dim iNumWords As Integer
        Dim iMax As Long
        Dim arPdfLines() As String
        Dim i As Integer
        Dim fso As FileSystemObject

        Set fso = New FileSystemObject
        If fso.FileExists(pstrPdfFilename) Then
            Set PDDoc = CreateObject("AcroExch.PDDoc")
            PDDoc.Open pstrPdfFilename
            Set PDPage = PDDoc.AcquirePage(PDDoc.GetNumPages() - 1)
            Set CArcoPoint = PDPage.GetSize()
            CAcroRect.Top = CArcoPoint.y
            CAcroRect.Left = 0
            CAcroRect.Right = CArcoPoint.x
            CAcroRect.bottom = 0
            Set PDTxtSelect = PDDoc.CreateTextSelect(PDDoc.GetNumPages() - 1, CAcroRect)
            If PDTxtSelect Is Nothing Then
                iNumWords = 0
                iMax = 0
                GetPDFLastLineText = ""
            Else
                iNumWords = PDTxtSelect.GetNumText
                iMax = iNumWords - 1
                Dim ii As Long
                For ii = 0 To iMax
                GetPDFLastLineText = GetPDFLastLineText & PDTxtSelect.GetText(ii)
            Next
        End If
        PDDoc.Close
    End If

    Set fso = Nothing
    Set PDDoc = Nothing
    Set CAcroRect = Nothing
    Set PDPage = Nothing
    Set PDTxtSelect = Nothing
    Set CArcoPoint = Nothing

End Function