17.05.2014 Views

PDFlib Text Extraction Toolkit (TET) Manual

PDFlib Text Extraction Toolkit (TET) Manual

PDFlib Text Extraction Toolkit (TET) Manual

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

3.10 Python Binding<br />

Installing the <strong>TET</strong> edition for Python. The Python extension mechanism works by<br />

loading shared libraries at runtime. For the <strong>TET</strong> binding to work, the Python interpreter<br />

must have access to the <strong>TET</strong> Python wrapper which will be searched in the directories<br />

listed in the PYTHONPATH environment variable. The name of Python wrapper depends<br />

on the platform:<br />

> Unix and OS X: tetlib_py.so<br />

> Windows: tetlib_py.pyd<br />

Error Handling in Python. The Python binding translates <strong>TET</strong> exceptions to native<br />

Python exceptions. The Python exceptions can be dealt with by the usual try/catch<br />

technique:<br />

try:<br />

...some <strong>TET</strong> instructions...<br />

except <strong>TET</strong>Exception:<br />

print("<strong>TET</strong> exception occurred:\n[%d] %s: %s" %<br />

((tet.get_errnum()), tet.get_apiname(), tet.get_errmsg()))<br />

3.10 Python Binding 37

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!