xralf
xralf

Reputation: 3692

How to change Ghostscript output file (in printer spooler) in Python

I'm trying to print a pdf file with ghostscript in Python3. I tried to write this code in Python.

os.chdir(documents_dir)
file = "myFile.pdf"
args = '"C:\\\\Program Files\\\\gs\\\\gs9.52\\\\bin\\\\gswin64c" ' \
       '-dBATCH ' \
       '-dNOPAUSE ' \
       '-dFitPage ' \
       '-sOutputFile="%printer%{}" ' \
       '-c "mark /UserSettings <</DocumentName ({})>> (mswinpr2) finddevice putdeviceprops setdevice" '.format(ptr_name, file)
ghostscript = args + os.path.abspath(file)
subprocess.call(ghostscript, shell=True)

It should print myFile.pdf so that in the printer spooler will be shown myFile.pdf as the job name.

How can I fix that command?

When the ptr_name is Microsoft Print to PDF the program ends up silently with empty PDF file. When I used another ptr_name it ended with this error message

enter image description here

Upvotes: 0

Views: 580

Answers (1)

KenS
KenS

Reputation: 31199

That's only a partial message, missing all the important text, and ite very hard to read. Rather than posting a picture of the text why not post the actual text (all of the back channel) ?

I don't speak Python, so how about stating (or indeed printing out) the contents of 'ghostscript' from your program (I'm assuming this is a string variable of some type). That would be useful for you too since it would let you see what your are tring to run and can look for errors in the string or syntax.

Clearly, if the command line works from the shell, there must be some difference in the command you are sending from Python.

Upvotes: 1

Related Questions