ScanOS/backend/app/backends/common.py

16 lines
559 B
Python

from PIL import Image
import ocrmypdf
def create_pdf(scanner):
images = []
for page in scanner.get_pages():
img = Image.open(f"/var/www/html/img/{page.filename}")
a4im = Image.new('RGB',
(int(210 * 200 / 25.4), int(297 * 200 / 25.4)),
(255, 255, 255))
a4im.paste(img, img.getbbox())
images.append(a4im)
images[0].save("/var/www/html/img/out.pdf", save_all=True, append_images=images[1:])
def ocr_pdf():
ocrmypdf.ocr('/var/www/html/img/out.pdf', '/var/www/html/img/final.pdf')