使用VB使用Acrobat SDK(Interop.Acrobat.dll)从pdf提取注释。 NET

时间:2018-10-23 13:48:34

标签: vb.net parsing text acrobat-sdk

我正在使用Acrobat SDK从pdf文件中提取文本。

这很好用。

我的代码虽然没有从注释中提取文本。

是否可以使用Acrobat SDK从注释/注释中提取文本?

我知道我可以使用iTextSharp,并且效果很好,但是我只想使用一个库。

以下代码:

Public Shared Function AdobePdfParse(strFileName As String, strTxtFromFile As String) As String
    'Note: A Reference to the Adobe Library must be set in Tools|References!
    'Note! This only works with Acrobat Pro installed on your PC, will not work with Reader
    Dim AcroApp As CAcroApp, AcroAVDoc As CAcroAVDoc, AcroPDDoc As CAcroPDDoc
    Dim AcroHiliteList As CAcroHiliteList, AcroTextSelect As CAcroPDTextSelect
    Dim PageNumber, PageContent, i, j, iNumPages
    Dim strResult As String

    AcroApp = CreateObject("AcroExch.App")
    AcroAVDoc = CreateObject("AcroExch.AVDoc")
    If AcroAVDoc.Open(strFileName, vbNull) <> True Then Exit Function

    AcroPDDoc = AcroAVDoc.GetPDDoc
    iNumPages = AcroPDDoc.GetNumPages

    Dim intfirst As Integer = 1

    For i = 0 To iNumPages - 1
        PageNumber = AcroPDDoc.AcquirePage(i)
        PageContent = CreateObject("AcroExch.HiliteList")
        If PageContent.Add(0, 9000) <> True Then Exit Function
        AcroTextSelect = PageNumber.CreatePageHilite(PageContent)
        ' The next line is needed to avoid errors with protected PDFs that can't be read
        On Error Resume Next
        For j = 0 To AcroTextSelect.GetNumText - 1
            strTxtFromFile = strTxtFromFile & AcroTextSelect.GetText(j)
        Next (j)
    Next i

    AcroAVDoc.Close(bNoSave:=0)
    AcroApp = Nothing
    AcroAVDoc = Nothing

    'Return sbTxtFromFile
    Return strTxtFromFile

End Function

0 个答案:

没有答案