21 lines
638 B
Python
21 lines
638 B
Python
from reportlab.pdfgen import canvas
|
|
from PIL import Image, ImageDraw
|
|
|
|
def create_pdf(filename, text):
|
|
c = canvas.Canvas(filename)
|
|
c.drawString(100, 750, text)
|
|
c.save()
|
|
print(f"Created {filename}")
|
|
|
|
def create_image(filename, text):
|
|
img = Image.new('RGB', (400, 100), color = (255, 255, 255))
|
|
d = ImageDraw.Draw(img)
|
|
# Default font is usually tiny, but readable by tesseract
|
|
d.text((10,10), text, fill=(0,0,0))
|
|
img.save(filename)
|
|
print(f"Created {filename}")
|
|
|
|
if __name__ == "__main__":
|
|
create_pdf("test_ocr.pdf", "Hello World PDF OCR")
|
|
create_image("test_ocr.png", "Hello World Image OCR")
|