Add OCR and image correction

This commit is contained in:
Oliver Traber 2024-07-07 00:30:13 +02:00
parent e74d3a4e27
commit e93117aeb4
Signed by: Bluemedia
GPG key ID: C0674B105057136C
13 changed files with 228 additions and 20 deletions

View file

View file

@ -0,0 +1,16 @@
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')

View file