pythonocrgdata-python-client

Python: what's the gdata method for uploading an image with enabled OCR?


as demonstrated on this PHP code, (http://code.google.com/p/gdata-samples/source/browse/trunk/doclist/OCRDemo/ocr.php?r=194 )

where an image can be uploaded to google docs that is automatically converted to text. i'm wondering how to do this in python. there is an "upload" method, but i'm just puzzled how to enable the OCR function.


Solution

  • assuming you've started here: http://code.google.com/apis/documents/docs/3.0/developers_guide_python.html

    you have an authenticated client object already created.

    f = open('/path/to/your/test.pdf')
    ms = gdata.data.MediaSource(file_handle=f, content_type='application/pdf', content_length=os.path.getsize(f.name))
    folder = "https://docs.google.com/feeds/default/private/full" # folder in google docs.
    entry = client.Upload(ms, f.name, folder_or_uri= folder + '?ocr=true') # ?ocr=true is the kicker
    

    specifying the folder_or_uri with the trailing ?ocr=true param is what causes the conversion to happen.

    after you create it, you can now export it as a txt document.