Is there a better way of doing this? I like the way your PDF-XChange Viewer Pro application performs this. It leaves the document open (or at least appears too) and works exactly like I want.
Here is my function in VB6. Any help would be greatly appreciated.
Code: Select all
Private Sub MakeSearchable()
Dim fso As FileSystemObject
Dim res As Long
Dim doc As Long
Dim sOutputFile As String
Dim sErrMsg As String
On Local Error GoTo EH
Screen.MousePointer = vbHourglass
Set fso = New FileSystemObject
pbar.Value = 0
pbar.Visible = True
MoveIntoStatusBar sbar, pbar, 2
Call OCR_Init(doc, PDF_SDK_KEY, PDF_CODE)
sOutputFile = QualifyPath(GetTempPathName) & "HLO_OCR.pdf" '<<-- THIS IS MY TEMP OCR FILE
CoPDFXCview1.CloseAllDocuments PXCVA_NoUI '<<-- HERE IS WHERE I HAVE TO CLOSE THE OPEN DOCUMENT (they only have 1 open at a time)
res = OCR_LoadA(doc, m_sTempFile)
If IS_DS_FAILED(res) Then
MsgBox "Could not load PDF file for OCR.", vbOKOnly + vbExclamation, "OCR Failed"
CoPDFXCview1.OpenDocument m_sTempFile 're-open document
GoTo EXIT_PROC
End If
SetCallback doc
Dim options As PXO_Options
options.blackList = ""
options.whiteList = ""
options.ImageFlags = OCR_Image_Autorotate
options.lang = PXO_English
options.raster_dpi = 300
options.RegionMode = OCR_Auto
options.DataPath = StrConv(QualifyPath(App.Path), vbUnicode)
options.accMode = 0
res = OCR_MakeSearchable(doc, options, 0)
If IS_DS_FAILED(res) Then
Err.Raise 1005, "MakeSearchable()", "Make searchable failed " & Str(res)
Else
res = OCR_SaveA(doc, sOutputFile)
If (IS_DS_FAILED(res)) Then
Err.Raise 1005, "MakeSearchable()", "Could not save OCR'd file."
Else
OCR_Delete doc
fso.DeleteFile m_sTempFile, True '<<--- HERE I HAVE TO DELETE THE ORIGINAL FILE WHICH IS IN THIS VARIABLE
fso.MoveFile sOutputFile, m_sTempFile '<<--- HERE I MOVE THE OUTPUT FILE OVER
CoPDFXCview1.OpenDocument m_sTempFile '<<--- HERE I RE-OPEN THE DOCUMENT FOR FURTHER EDITING
MsgBox "Make searchable successful!", vbOKOnly + vbInformation, "OCR Successful"
m_bModified = True
End If
End If
GoTo EXIT_PROC
Resume 'for debugging
EH:
sErrMsg = "Unexpected exception in procedure MakeSearchable of Form frmScan" & vbCrLf & _
Err.Number & " - " & Err.Description & vbCrLf & _
"Line#: " & Erl
'' Msgbox sErrMsg, vbCritical + vbOkOnly, "Unexpected exception"
RaiseEvent WriteLog(sErrMsg)
RaiseEvent ScanError("Unexpected Exception", sErrMsg)
EXIT_PROC:
OCR_Delete doc
pbar.Value = 0
pbar.Visible = False
sbar.Panels(1).Text = ""
Screen.MousePointer = vbDefault
End Sub
Kindest Regards,
Nelson