Can I keep the PDF open during OCR?

PDF-X OCR SDK is a New product from us and intended to compliment our existing PDF and Imaging Tools to provide the Developer with an expanding set of professional tools for Optical Character Recognition tasks

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Tracker Supp-Stefan

nlopes
User
Posts: 33
Joined: Tue Aug 24, 2010 3:44 am

Can I keep the PDF open during OCR?

Post by nlopes »

I am using the PDF-XChange Viewer Pro SDK and have a PDF document opened on the screen. I'm implementing the ability to let them OCR the document and am using the code example for VB6 to do this. The thing that I'd like to do is keep the PDF open (shown) on the screen - while the OCR is in progress. However, since the PDF is open in the viewer - I'm currently needing to close it. I then read it into the OCR engine, perform the OCR while showing a progress bar, and then save it to a different output file (can't save to the same file as it errors). If all goes well, the last step I have to delete the original PDF file and rename the OCR'd output file to the original filename and re-open that in the viewer. This way any further changes made to the PDF can be saved.

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
technovia
User
Posts: 11
Joined: Wed Feb 22, 2012 3:59 pm

Re: Can I keep the PDF open during OCR?

Post by technovia »

Hi Nelson

Perhaps you may use a "tiny" local http server (eg : ZMWS http://www.zmws.com/doc/spip.php?article14 excellent ...but no english doc.) and load the file to display using URL (eg: CoPDFXCview1.Src= "http://192.168.1.xxx/myfile.pdf")

In this case, CoPDFXCview1 copies C:\Myfolder\myfile.pdf in the Tracker-XChange temp folder (eg: C:\windows\temp\XCHANGE) before loading leaving C:\Myfolder\myfile.pdf unchanged.

Then you can load C:\Myfolder\myfile.pdf to OCR and save it. After OCR, you have just to load the new OCRed C:\Myfolder\myfile.pdf

But it is not a very simple way...
Best regards
Gérard
User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2353
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: Can I keep the PDF open during OCR?

Post by Vasyl-Tracker Dev Team »

The thing that I'd like to do is keep the PDF open (shown) on the screen - while the OCR is in progress. However, since the PDF is open in the viewer - I'm currently needing to close it. I then read it into the OCR engine, perform the OCR while showing a progress bar, and then save it to a different output file (can't save to the same file as it errors).
For your case you have two ways:

1. You may create copy of original file to show it by ActiveX and use an original file for OCR and saving the OCR-result to this file.
2. Or you may close an original file which opened in Viewer ActiveX Control, save OCR-result to this file and then re-open this file in ActiveX.

HTH.
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
nlopes
User
Posts: 33
Joined: Tue Aug 24, 2010 3:44 am

Re: Can I keep the PDF open during OCR?

Post by nlopes »

Thank you for the replies. I figured this out.

My solution was to save the open document in the PDF Viewer using the SaveDocumentCopy parameter of the SaveDocument method. The PDF-XChange Viewer automatically saves a copy of the document (to a specified name or automatically generated one) and, if successful, automatically loads the copy and closes the original document. This is very fast and releases my original PDF file from being open. I then use the copied file (that is now loaded in the viewer) to load as the OCR document to process. I can then save it to the original filename when the OCR is complete. Finally, I simply re-open the original file in the viewer and delete the copy. Works great! I'm sure there might be a more correct way of doing this (perhaps in memory using a stream) - but I'm stuck in VB6 on this app - so this works. Thanks again.

Best Regards,

Nelson
User avatar
Paul - Tracker Supp
Site Admin
Posts: 6901
Joined: Wed Mar 25, 2009 10:37 pm
Location: Chemainus, Canada

Re: Can I keep the PDF open during OCR?

Post by Paul - Tracker Supp »

:)
Best regards

Paul O'Rorke
Tracker Support North America
http://www.tracker-software.com
Walter-Tracker Supp
User
Posts: 381
Joined: Mon Jun 13, 2011 5:10 pm

Re: Can I keep the PDF open during OCR?

Post by Walter-Tracker Supp »

Glad you've found a working solution.

-Walter
janette73
User
Posts: 1
Joined: Thu Sep 06, 2012 3:53 pm

Re: Can I keep the PDF open during OCR?

Post by janette73 »

PDF-XChange Viewer PRO SDK contains both the Simple DLL SDK providing the developer with a set of functions to create a means to View or Print PDF files within a window embedded in their software application.
Nico - Tracker Supp
User
Posts: 205
Joined: Fri May 18, 2012 8:41 pm

Re: Can I keep the PDF open during OCR?

Post by Nico - Tracker Supp »

Thank you janette73 for your clarification.