Using pypdfocr library from inside a python script

How can you run pypdfocr from within a Python script, unlike the command line?

This question How to call pypdfocr functions to use them in a python script? fits the answer I want, but not quite there.

import pypdfocr
from pypdfocr import pypdfocr
from pypdfocr.pypdfocr import PyPDFOCR as pocr

filepath = 'C:/myfolder/myPDF.pdf'

newfile = pocr.run_conversion(filepath)

This causes an error:

Unbound method  run_conversion must be called with PyPDFOCR instance as first argument.

Can someone help me fill in a (probably obvious) missing piece?

+1
source share
2 answers

The problem is that you are trying to run run_conversion without an object.

run_conversion- class method PyPDFOCR. Therefore, to run the method, you need an object of this class.

PyPDFOCR (, my_ocr), :

newfile = my_ocr.run_conversion(filepath)
0

.

cmd = "pypdfocr '"+str(file)+"'"
os.system(cmd)
0

Source: https://habr.com/ru/post/1657434/


All Articles