I am from Brazil, I would like your help.
I want to know how to use VBA's commands to read and to find text inside of Pdf file, if posible send to me code in VBA
Thanks you
I am from Brazil, I would like your help.
I want to know how to use VBA's commands to read and to find text inside of Pdf file, if posible send to me code in VBA
Thanks you
Option Compare DatabaseOption Explicit
Dim gApp As Object Sub AcrobatFindText()'IAC objectsDim gAvDoc As Object
'variablesDim Resp 'For message box responsesDim gPDFPath As String
Dim sText As String 'String to search forDim sStr As String 'Message stringDim foundText As Integer 'Holds return value from "FindText" method 'hard coding for a PDF to open, it can be changed when needed.gPDFPath = "C:\mydocument.pdf" 'Initialize Acrobat by creating App objectSet gApp = CreateObject("AcroExch.App")gApp.Hide 'Set AVDoc objectSet gAvDoc = CreateObject("AcroExch.AVDoc") ' open the PDFIf gAvDoc.Open(gPDFPath, "") ThensText = "factory"'FindText params: StringToSearchFor, caseSensitive (1 or 0), WholeWords (1 or 0), ResetSearchToBeginOfDocument (1 or 0)foundText = gAvDoc.FindText(sText, 1, 0, 1) 'Returns -1 if found, 0 otherwise Else' if failed, show error messageResp = MsgBox("Cannot open" & gPDFPath, vbOKOnly)End If
If foundText = -1 Then
'compose a messagesStr = "Found " & sTextResp = MsgBox(sStr, vbOKOnly)Else' if failed, show error messageResp = MsgBox("Cannot find" & sText, vbOKOnly)End If
gApp.Show
gAvDoc.BringToFront
End Sub
Sub AcrobatPageCount()
Dim Resp
'IAC objectsDim gPDDoc As ObjectDim gAvDoc As Object 'variablesDim gPDFPath As String
Dim rc As Boolean
Dim sStr As String
Dim sName As String
Dim lNum As Integer
'hard coding for a PDF to open, it can be changed when needed.gPDFPath = "C:\mydocument.pdf" 'Initialize Acrobat by creating App objectSet gApp = CreateObject("AcroExch.App")gApp.Hide
'Set AVDoc objectSet gAvDoc = CreateObject("AcroExch.AVDoc") ' open the PDFIf gAvDoc.Open(gPDFPath, "") Then 'Set PDDoc object and get some dataSet gPDDoc = gAvDoc.GetPDDoc()lNum = gPDDoc.GetNumPages()sName = gPDDoc.GetFileName() 'compose a messagesStr = "PDF file " & sName & " is loaded in Acrobat through IAC program." & vbCrLf & "The PDF document has " & lNum & " pages." & vbCrLf & "The program is over."Resp = MsgBox(sStr, vbOKOnly)
Else
' if failed, show error messageResp = MsgBox("Cannot open " & gPDFPath & vbCrLf & "The program is over.", vbOKOnly)End If'I have tried various combinations of the lines below and earlier in the routine to get the application to close and/or hide in a predictable way. But no luck.'gApp.ShowgAvDoc.Close (1)'gApp.ExitgApp.Minimize (1)
'gApp.ShowEnd Sub
'Create a custom toolbarSub Auto_Open() 'Runs automatically when the file is openedDim MyToolbar As CommandBarDim MyButton As CommandBarButtonDim MyToolbarName As StringDim Resp
'Give the toolbar a nameMyToolbarName = "PDFtools" ' First, delete the toolbar if it already existsOn Error Resume Next ' so that it doesn't stop on the next line if the toolbar does not existCommandBars(MyToolbarName).Delete ' Build the command barOn Error Resume Next ' so that it doesn't stop on the next line if the toolbar's already thereSet MyToolbar = CommandBars.Add(Name:=MyToolbarName, Position:=msoBarTop) On Error GoTo ErrorHandler
' Add a button to the new toolbarSet MyButton = MyToolbar.Controls.Add(Type:=msoControlButton)
' MsoButtonStyle constants can be any one of:'msoButtonAutomatic'msoButtonIcon (Button displays Icon only)'msoButtonCaption (Button displays text only)'msoButtonIconAndCaption'msoButtonIconAndCaptionBelow'msoButtonIconAndWrapCaption'msoButtonIconAndWrapCaptionBelow'msoButtonWrapCaption (Read/write Long) ' Set some of the button's propertiesWith MyButton.TooltipText = "Open PDF and find text" 'Tooltip text when mouse is placed over button.Caption = "PDF Find Text" 'Text to be displayed on button.OnAction = "AcrobatFindText" 'Name of routine to run when clicked.Style = msoButtonCaption 'Make button display text onlyEnd With ' Add another button to the new toolbarSet MyButton = MyToolbar.Controls.Add(Type:=msoControlButton)
' Set some of the button's propertiesWith MyButton
.TooltipText = "Get number of pages in PDF" 'Tooltip text when mouse is placed over button.Caption = "PDF Page Count" 'Text to be displayed on button.OnAction = "AcrobatPageCount" 'Name of routine to run when clicked.Style = msoButtonCaption 'Make button display text only.BeginGroup = True 'Put a separator line between the buttonsEnd With MyToolbar.Visible = True On Error GoTo 0 'Resume default error handling NormalExit:
' MsgBox "Note: This version is still under development. " & _' "Please be careful!"Exit Sub ' so it doesn't go on to run the errorhandler code ErrorHandler:
'Just in case there is an errorMsgBox Err.Number & vbCrLf & Err.DescriptionResume NormalExit:End Sub
'Delete the custom toolbar when you close the databaseSub Auto_Close() 'Runs automatically when the file is closedDim bar, MyToolbarName As String ' Specify the toolbar nameMyToolbarName = "PDFtools" ' Delete the toolbarFor Each bar In CommandBarsIf bar.Name = MyToolbarName Thenbar.DeleteEnd IfNext bar
End Sub
Checkout the documentation at:
http://www.adobe.com/devnet/acrobat/?tab:downloads=1/
Sincerely,
Jim