zonal OCR sample in VB/C#.NET needed

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

djdrew_BOLT
User
Posts: 4
Joined: Wed Nov 28, 2012 6:44 pm

zonal OCR sample in VB/C#.NET needed

Post by djdrew_BOLT »

can anyone provide sample code/project illustrating this?

here is my current relevant code attempt

Code: Select all

 datapath = Application.StartupPath & "\ocrdats"  
        Dim region As PXO_InputField
        region.blackList = VarPtrAny(wlist)
        region.whiteList = VarPtrAny(blist)
        region.top = 110
        region.bottom = 200
        region.nPage = 1
        region.left = 106
        region.right = 209
        Dim options As new PXO_Options
        options.blackList = VarPtrAny(wlist)
        options.whiteList = VarPtrAny(blist)
        options.ImageFlags = OcrCommon.OCR_ImageProcessingFlags.OCR_Image_NoRotate '& OcrCommon.OCR_ImageProcessingFlags.OCR_Image_SuppressOutput 'SuppressOutput only saves a hidden text pdf (will combine with original image pdf). Also turned off rotate (is actually deskew) so text positions match up with image when it is merged back together in a separate function.
        options.lang = 0 '0 = defaults to english, not currently supporting other languages
        options.raster_dpi = 300 'less than 300 and OCR suffers
        options.RegionMode = OcrCommon.OCR_RegionMode.OCR_Auto
        options.DataPath = VarPtrAny(datapath)
        options.accMode = 0

        '9/21/12 allows specifying a page number to ocr. Is 0 based
        Dim pg As Integer 'pg will either be a pointer to newpagelist or 0
        pg = 0

        '9/21/12 end page number

        
        Dim textout As String = ""
        textout = VarPtrAny(textout)
        'res = OCR_MakeSearchable(doc, options, pg) 'runs the actual OCR  whole page ocr working
        res = OCR_GetField(doc, options, textout, region, 1)
        'res = OCR_GetText(doc, options, textout, pg, )
        'SysFreeString(textout)
        OCR_SaveA(doc, "OCRFinal.pdf")
as you can see i've made two/three different attempts see commented out res = lines

Any suggestions or help is appreciated Thanks
Walter-Tracker Supp
User
Posts: 381
Joined: Mon Jun 13, 2011 5:10 pm

Re: zonal OCR sample in VB/C#.NET needed

Post by Walter-Tracker Supp »

It is unnecessary to append '\ocrdats' to the data directory; this is hardcoded into the library, so that if you specify "c:\myproject", OCR will look for language files in "c:\myproject\ocrdats". In your case, it will be looking for "(Applicationpath)\ocrdats\ocrdats\".

I realize this is an unnecessary restriction, but since we released with this behaviour in place we haven't seen fit to remove it.

It'll be changed in the new SDK versions coming out in 2013, so that the path provided will be exactly the path to search for language files.
djdrew_BOLT
User
Posts: 4
Joined: Wed Nov 28, 2012 6:44 pm

Re: zonal OCR sample in VB/C#.NET needed

Post by djdrew_BOLT »

thanks, but either way it still doesn't work, error code is -2113732591
Walter-Tracker Supp
User
Posts: 381
Joined: Mon Jun 13, 2011 5:10 pm

Re: zonal OCR sample in VB/C#.NET needed

Post by Walter-Tracker Supp »

Here's a quick and dirty C# example which does include both a call to OCR_MakeSearchable() and OCR_GetFields().

I realize you posted VB code, but you mentioned both C# and VB and at the moment (under a big deadline) it is most expedient to give this particular example.

It might help if you could provide the PDF you are trying to OCR, or one that at least reprdoces the problems you are having. Is the error code returned from OCR_GetFields() or is it from OCR_MakeSearchable()? Remember coordinates are in PDF points, and specifying "1" for the flags (last argument) means the top left corner is the origin, with the positive Y axis pointing down.
You do not have the required permissions to view the files attached to this post.
djdrew_BOLT
User
Posts: 4
Joined: Wed Nov 28, 2012 6:44 pm

Re: zonal OCR sample in VB/C#.NET needed

Post by djdrew_BOLT »

your sample works, probably because you helped develop the sdk lol, but mine still does not, although it no longer returns an error code
User avatar
John - Tracker Supp
Site Admin
Posts: 5219
Joined: Tue Jun 29, 2004 10:34 am
Location: United Kingdom

Re: zonal OCR sample in VB/C#.NET needed

Post by John - Tracker Supp »

Certainly helps to be involved at the 'coal face' :)

If you still have problems - perhaps strip your code down to that which is relevant and send to us - along with a specific PDF and I am sure walter can apply a little 'magic.

cheers
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.

Best regards
Tracker Support
http://www.tracker-software.com
djdrew_BOLT
User
Posts: 4
Joined: Wed Nov 28, 2012 6:44 pm

Re: zonal OCR sample in VB/C#.NET needed

Post by djdrew_BOLT »

i still don't have a clue what i was doing wrong, but i built a new fresh project and it's all fine *shrugs* thanks everyone
User avatar
John - Tracker Supp
Site Admin
Posts: 5219
Joined: Tue Jun 29, 2004 10:34 am
Location: United Kingdom

Re: zonal OCR sample in VB/C#.NET needed

Post by John - Tracker Supp »

Wierd - but pleased all is well :)
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.

Best regards
Tracker Support
http://www.tracker-software.com