'//mr:: 调用acrobat的方法, 大小写都可以.'//mr:: 不需要AcroExch.App这个对象.Sub GetAnnotationFromPDF()Dim AcrApp As Acrobat.AcroAppDim AcrAvDoc As Acrobat.AcroAVDocDim pdDoc As Acrobat.CAcroPDDocDim Jso As ObjectDim Annots() As VariantDim Annot As VariantDim Props As ObjectDim strContent, strSubType, strAuthor, strSubject As String'Set AcrApp = New Acrobat.AcroApp'Set AcrApp = CreateObject("AcroExch.App")'Set AcrAvDoc = AcrApp.GetActiveDoSet pdDoc = CreateObject("AcroExch.PDDoc")pdDoc.Open ("C:\Users\OneCrazyStone\Desktop\H12_hdevelop_users_guide_JOM.pdf")'Set pdDoc = AcrAvDoc.GetPDDocSet Jso = pdDoc.GetJSObjectJso.syncAnnotScan '//mr?? 这句还不能少Annots = Jso.getAnnots()Dim i As Integeri = 0For 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 NextSet Props = NothingSet Annot = Nothing'Set Annots = NothingErase AnnotsSet Jso = NothingSet pdDoc = NothingSet AcrAvDoc = Nothing
Public Sub Main() 'Dim SOURCE_DOCUMENT As String = System.Windows.Forms.Application.StartupPath "\..\..\..\..\TestFiles\FormSample.pdf" 'C:\Users\OneCrazyStone\Desktop\H12_hdevelop_users_guide_JOM.pdf Dim SOURCE_DOCUMENT As String = "C:\Users\OneCrazyStone\Desktop\H12_hdevelop_users_guide_JOM.pdf" Dim DATA_FILE As String = System.Windows.Forms.Application.StartupPath "\..\..\..\..\TestFiles\data.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 SubErrorHandler: MsgBox("Error Occured: " & Err.Description) Resume EndSubEnd Sub
联系客服