I am using OCR to scan invoices, and I have a large collection of PDFs. The code I am using to convert the PDF to PNG is the following:
import fitz
file_path = "my_file.pdf"
dpi = 500
zoom = dpi / 72 # zoom factor, standard: 72 dpi
magnify = fitz.Matrix(zoom, zoom)
doc = fitz.open(f'my_file.pdf')
for page in doc:
pix = page.get_pixmap(matrix=magnify)
pix.save(f"page-{page.number}.png")
I then take each PNG and perform OCR on it.
Now I don't want to save the new png file each time and accumulate hundreds of stored PNG's, rather I just want the OCR output saved. Is there a way to keep the format of PNG just within the code and NOT have to save each page of the PDF as a PNG in my folder?