WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE with Acrobat Viewer

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Read Text from PDF Document


;Winbatch 2007C - read text from PDF Document
;
;
;Stan Littlefield August 23, 2007
;////////////////////////////////////////////////////////////////////////////
GoSub udfs
IntControl(73,1,0,0,0)

types="Acrobat PDF|*.pdf|"
cPDF=AskFilename("PDF File to Search Text", DirScript(), types, "", 1)
If cPDF=="" Then Exit
Content=""
oApp = CreateObject("AcroExch.App")
oAVDoc = CreateObject("AcroExch.AVDoc")

If oAvDoc.Open(cPDF,"") Then
   oApp.Show()
   oAVDoc = oApp.GetActiveDoc()
Else
   Display(2,"Unable to open the PDF-file", "Program Terminating")
   Goto End
EndIf

BoxOpen("Please Wait",cPDF)
oPDDoc = oAVDoc.GetPDDoc

For i = 0 To oPDDoc.GetNumPages -1
   PageNumber = oPDDoc.AcquirePage(i)
   PageContent = CreateObject("AcroExch.HiliteList")
   BoxText("Processing Page ":i)
   If !PageContent.Add(0, 9000) Then Break
   AcroTextSelect = PageNumber.CreatePageHilite(PageContent)

   For j = 0 To AcroTextSelect.GetNumText - 1
      Content = Content:AcroTextSelect.GetText(j)
   Next
   PageContent=0
Next

:End
PageContent=0
oPDDoc=0
oAVDoc.Close(@TRUE)
oApp.CloseAllDocs()

; Apprently the QUIT method does not work if the application is visible (if the user is in control of the application).
; In such cases, if the Show method had previously been called, you can call Hide and then Exit."
oApp.Hide()
oApp.Exit()

oAVDoc = 0
oApp = 0

;you would probably want to write the contents to a file
;or process each page
Message(cPDF,Content)
Exit
;////////////////////////////////////////////////////////////////////////////


:WBERRORHANDLER
ErrorProcessing(1,1,0,0)
Exit
;////////////////////////////////////////////////////////////////////////////


:CANCEL
Exit
;////////////////////////////////////////////////////////////////////////////

:udfs
#DefineSubRoutine ErrorProcessing(deleteIni,showerr,logfile,Err_Array)
If VarType(Err_Array) ==256
   WbError = Err_Array[0]
   wberrorhandlerline = Err_Array[1]
   wberrorhandleroffset = Err_Array[2]
   wberrorhandlerassignment = Err_Array[3]
   wberrorhandlerfile = Err_Array[4]
   wberrortextstring = Err_Array[5]
   wberroradditionalinfo = Err_Array[6]
   wberrorinsegment = Err_Array[7]
Else
   WbError = LastError()
EndIf
WbTextcode = WbError
If WbError==1668||WbError==2669||WbError==3670
   ; 1668 ; "Minor user-defined error"
   ; 2669 ; "Moderate user-defined error"
   ; 3670 ; "Severe user-defined error"
   WbError = ItemExtract(1,IntControl(34,-1,0,0,0),":")
   WbTextcode = -1
EndIf
WbErrorString = IntControl(34,WbTextcode,0,0,0)
WbErrorDateTime = TimeYmdHms()
WbErrorFile = StrCat(DirWindows(0),"WWWBATCH.INI")
If deleteIni
   FileDelete(WbErrorFile)
   IniWritePvt(WbErrorDateTime,"CurrentScript",WbErrorHandlerFile      ,WbErrorFile)
   IniWritePvt(WbErrorDateTime,"ErrorValue"   ,WbError                 ,WbErrorFile)
   IniWritePvt(WbErrorDateTime,"ErrorString"  ,WbErrorString           ,WbErrorFile)
   IniWritePvt(WbErrorDateTime,"ScriptLine"   ,WbErrorHandlerLine      ,WbErrorFile)
   IniWritePvt(WbErrorDateTime,"ScriptOffset" ,WbErrorHandlerOffset    ,WbErrorFile)
   IniWritePvt(WbErrorDateTime,"VarAssignment",WbErrorHandlerAssignment,WbErrorFile)
   IniWritePvt(WbErrorDateTime,"VarInSegment" ,WbErrorInSegment,WbErrorFile)
   IniWritePvt("","","",WbErrorFile)
EndIf
WbErrorMsgText = StrCat(WbErrorDateTime,@CRLF)
WbErrorMsgText = StrCat(WbErrorMsgText,"Current Script: ",WbErrorHandlerFile,@CRLF)
WbErrorMsgText = StrCat(WbErrorMsgText,"Error# [",WbError,"]",@CRLF)
WbErrorMsgText = StrCat(WbErrorMsgText,"Error Text: ",wberrortextstring,@CRLF)
WbErrorMsgText = StrCat(WbErrorMsgText,"[Extended Information] ",wberroradditionalinfo,@CRLF,@CRLF)
WbErrorMsgText = StrCat(WbErrorMsgText,"On Line:",@CRLF,WbErrorHandlerLine,@CRLF)
;WbErrorMsgText = StrCat(WbErrorMsgText,"Offset: ",WbErrorHandlerOffset,@CRLF)
If (WbErrorHandlerAssignment>"") Then %WbErrorHandlerAssignment% = "UNKNOWN"
WbErrorMsgText = StrCat(WbErrorMsgText,"Assignment/Variable: ",WbErrorHandlerAssignment,@CRLF)
If (WbErrorInSegment>"") Then WbErrorMsgText = StrCat(WbErrorMsgText,"In UDF/UDS: ",WbErrorInSegment,@CRLF)
If logfile
   cSep = StrCat(StrFill("=",50),@CRLF)
   cLogFile = StrCat(DirScript(),"log.err")
   If ! FileExist(cLogFile) Then FilePut(cLogFile,StrCat("Error Log",@CRLF,cSep))
   FilePut(cLogFile,StrCat(FileGet(cLogFile),WbErrorMsgText,cSep))
   Display(2,"An Error Occured",StrCat("written to ",cLogFile))
Else
   If showerr
      WbErrorMsgText = StrCat(WbErrorMsgText,"[THIS ERROR NOT WRITTEN TO LOG FILE]",@CRLF)
      Message("An Error Was Encountered",WbErrorMsgText)
   EndIf
EndIf
Return(1)
#EndSubRoutine

Return
;////////////////////////////////////////////////////////////////////////////
--------------------------------------------------------------------------------
Article ID:   W17447
File Created: 2011:03:03:12:58:32
Last Updated: 2011:03:03:12:58:32