I am trying to extract images from PDF files, and I successfully achieve this by running this command in a bash shell:
$ pdfimages -j "google.pdf" conv
However, when trying to run this exact same command via subprocess
, within my flask app:
subprocess.Popen(["pdfimages", "-j", "-", "conv"], stdin=subprocess.PIPE).communicate(input=file.read())
It does not completes the extraction, and gives this error:
Syntax Warning: May not be a PDF file (continuing anyway)
Syntax Error: Couldn't find trailer dictionary
Syntax Error: Couldn't read xref table
Why is this happening? What is the correct way to call/start a subprocess in pythonanywhere?