Hi,
I'm not a big Python programmer therefore I ask for support/guidance from more experienced ones. The result might be a great add-in for the marketplace serving lots of customers in the pharma and potentially other industries.
Background:
Many companies are having procedures where operators add hand-written numbers and comments into a predifined and structured sheet of paper which will then be scanned into a PDF. Attached an example. These inputs need to be extracted and analysed.
The issue is that the scanned paper is an image in PDF and cannot be imported via the PDF import wizard. In addition the handwritten code is probably difficult to identify correctly. The current solution for many pharmaceutical companies is that people have to enter that data manually, sometimes 2h and that 2-5 times a week. Having an option to extract at least some of the information more automatically would be a big value to them.
I did some research, one could use python to extract the images from the PDF and then extract the text from the images using some packages. Here is a process I found to do this.
- Install pytesseract (OCR engine) and pdf2image (to convert PDF pages to images).
- Workflow:
- Convert PDF pages to images.
- Run OCR on each image using pytesseract.
- Save extracted text to a file or process further.
Here is where I need some help/support. The goal would be to use the attached document as a proof of concept. If that would work we may create an add-in and put that on the marketplace.
I bet this would be a big relief for many companies and make them even more sticky to JMP.
Any volunteers?
@Paul_Nelson
PS: (from Copilot)
Below is a complete Python script that converts a scanned PDF into text using pdf2image and pytesseract:
Python
from pdf2image import convert_from_path
import pytesseract
# Path to your scanned PDF file
pdf_path = 'scanned_document.pdf'
# Convert PDF pages to images
pages = convert_from_path(pdf_path)
# Initialize a variable to store extracted text
extracted_text = ""
# Loop through each page and apply OCR
for page_number, page in enumerate(pages, start=1):
text = pytesseract.image_to_string(page)
extracted_text += f"\n--- Page {page_number} ---\n{text}\n"
# Save the extracted text to a file
with open('extracted_text.txt', 'w', encoding='utf-8') as f:
f.write(extracted_text)
print("OCR extraction completed. Text saved to extracted_text.txt")
I think pytesseract would only work with the typewritten portions of the PDF. You'd need something more for the handwriting recognition. Perhaps this link could be a starting point?