Jun-11-2022, 04:20 AM
Quote:refers to line 3 of your code. This needs to be a file name of a pdf file.
Thanks; I knew it was line 3 , but just wasn't specified correctly. The following ..
pdfs = r"~/Downloads/OCR/Tests_20220530.pdf" didn't work
pdfs = r"/home/********/Downloads/OCR/Tests_20220530.pdf" worked
pdfs = r"Tests_20220530.pdf" worked
As I wanted to have the filename as an argument, tried this
from pdf2image import convert_from_path import sys # Print total number of arguments print ('Total number of arguments:', format(len(sys.argv))) # Print all arguments print ('Argument List:', str(sys.argv)) # Print arguments one by one print ('First argument:', str(sys.argv[0])) print ('Second argument:', str(sys.argv[1])) filename = sys.argv[1] pdfs = r"(filename)" pages = convert_from_path(pdfs, 350) i = 1 for page in pages: image_name = "Page_" + str(i) + ".jpg" page.save(image_name, "JPEG") i = i+1$ python3 PDF_to_Image1.py Tests_20220530.pdf
Error:Total number of arguments: 2
Argument List: ['PDF_to_Image1.py', 'Tests_20220530.pdf']
First argument: PDF_to_Image1.py
Second argument: Tests_20220530.pdf
Traceback (most recent call last):
File "/home/********/.local/lib/python3.9/site-packages/pdf2image/pdf2image.py", line 479, in pdfinfo_from_path
raise ValueError
ValueError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/********/Downloads/OCR/PDF_to_Image1.py", line 17, in <module>
pages = convert_from_path(pdfs, 350)
File "/home/********/.local/lib/python3.9/site-packages/pdf2image/pdf2image.py", line 98, in convert_from_path
page_count = pdfinfo_from_path(pdf_path, userpw, poppler_path=poppler_path)["Pages"]
File "/home/********/.local/lib/python3.9/site-packages/pdf2image/pdf2image.py", line 488, in pdfinfo_from_path
raise PDFPageCountError(
pdf2image.exceptions.PDFPageCountError: Unable to get page count.
I/O Error: Couldn't open file '(filename)': No such file or directory.