I have a python script for converting PDFs to images. I have tested it and found that it works, but I would like to call it within a poweshell script.
The powershell script I have seems to actually run, but doesn't actually do anything. It is:
$env:Path += ";C:\Program Files (x86)\Python37-32"; #path to where I have python installed
$env:PATHEXT += ";.py"
$arg1 = 'C:\Localdata\TestPath' #path to target PDF
$arg2 = 'sample.pdf' #tried both double and single quotes here, doesn't seem to help
$arg3 = 1 #starting page to convert
$arg4 = 2 #ending page to convert
$arg5 = 'C:\Localdata\testpath' #path to save jpg
$arg6 = "temp" #used in jpeg name along with page number
$arg7 = 'C:\Localdata\AutoPQR\PDF2Image.py' # path to python file
python $arg7 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6
The python script is:
def PDFtoImage(targetpath, PDF, startpage, endpage, savepath, savename):
os.chdir(targetpath)
startindex = startpage-1
endindex = endpage-1
i = startindex
pages = convert_from_path(PDF, 0)
while i<endpage:
pages[i].save(savename + str(i+1) +".jpg" , 'JPEG')
i = i+1
Am I being daft or missing something? Please provide me suggestions, thanks!!
*Update, upon the advice of those in the comments I have tried the following, unsuccessfully
Start-Process -FilePath 'C:\Program Files (x86)\Python37-32\python.exe' -ArgumentList 'C:\Localdata\Testpath\PDF2Image.py' 'C:\Localdata\Testpath' "sample.pdf" 1 2 'C:\Localdata\Testpath' "temp"
and
Start-Process -FilePath 'C:\Localdata\Testpath\PDF2Image.py' -ArgumentList 'C:\Localdata\Testpath' "sample.pdf" 1 2 'C:\Localdata\Testpath' "temp"