gali8 / Tesseract-OCR-iOS

Tesseract OCR iOS is a Framework for iOS7+, compiled also for armv7s and arm64.
http://www.nexor.it
MIT License
4.22k stars 949 forks source link

How to get log file and export output to pdf file? #172

Closed greenwind1202 closed 9 years ago

greenwind1202 commented 9 years ago

I'm trying to create demo iOS app using Tesseract-OCR-iOS library. I want to get log file and write output to pdf file. After investigating, I set some parameter into config file as below: debug_file tesseract.log tessedit_create_pdf T

But I can not find log file and *.pdf file. Where am I wrong?

Thanks and best regards.

ws233 commented 9 years ago

I might be wrong, but an issue might occur due to the forbidden write permissions in the app root directory. Can you prove that tess doesn't try to create those files in the current folder? Can you also try any absolute full paths to any writable folders?

ws233 commented 9 years ago

Exactly! I did try an absolute path to Documents folder, and a log file has appeared in it.

greenwind1202 commented 9 years ago

Thanks for your quick reply but can you get more detail? How to set absolute path? Because I aslo tried to set absolute path by code: NSString root = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSString logFile = [root stringByAppendingPathComponent:@"tesseract.log"]; [tesseract setVariableValue:logFile forKey:@"debug_file"];

Although log file is created but content is empty.

ws233 commented 9 years ago

I put the following line to the config file: debug_file /Users/yourUser/Documents/tesseract.log Also I did try the code in simulator. The log is not empty. But you should at least initialize a tesseract and perhaps recognize an image.

I guess that 'debug_file' is an init time variable. So it's possible to set it only from the config file, or config dictionary while call to init... Don't use 'setVariableValue:forKey' for that purpose. It won't work.

greenwind1202 commented 9 years ago

Thank you so much. I can get log file without problem. I have another question about generate output to pdf file. Currently, does library support to do this?

ws233 commented 9 years ago

Yes, it is. But as I've already told the default output for pdf is the executable folder, which is write protected. You should try to change output dir, if it's possible with some config variables. If it's not, you might take a look on upstream tesseract sources. TessPDFRenderer could be a starting point for your investigations. If you succeed pls don't forget to submit a pull request, so we all are able to use this feature.

greenwind1202 commented 9 years ago

Yes.. I got it. That's exactly what I thought. :). Again, thank you for your support.

ws233 commented 9 years ago

You're welcome. Feel free to ask any questions. We'll try to provide you with so many support as we can.

ws233 commented 9 years ago

Finally, I've written code, which generates pdf NSData, which could be saved to Documents folder, for example. Inspite of tesseract generates an output, it's corrupted. So I'm trying to understand what's wrong with my code.

ws233 commented 9 years ago

I've succeeded with this and with PDF output. I'll upload it soon.

ws233 commented 9 years ago

Pls, refer to #186.

The following things should be mentioned regarding the patch:

There are still few issues with PDF output: