-1

I have exhausted all efforts and am still stumped as to why this simple program will not output a tiff file. It should only be pulling one PDF file converting it to a tiff and ehancing the image. I am not a great programmer by any means, but it doesnt seem like this should be to difficult... I think my problem is I am having a hard time getting ghostscript to invoke at all. I have tried (gs, gswin32c, gswin32, gswin64, gswin64c, gsoso) Still no output... Here is my Python script.


fob=open('C:/Users/Tanner/Desktop/1page.pdf','r')        
'gswin64.exe',
'-q',
'-dNOPAUSE',
'-dBATCH',
'-r800',
'-sDEVICE=tiffg4',
'-sPAPERSIZE=a4',
'-sOutputFile=%s %s' % ('C:/My Documents','C:/Users/Tanner/Desktop/1page.pdf')
cleg
  • 4,464
  • 5
  • 30
  • 50
Blairt
  • 17
  • 3

1 Answers1

2

All you're doing with that script is creating a bunch of 1-tuples but not assigning them to anything. e.g.

>>> '-q',
('-q',)
>>> '-dNOPAUSE',
('-dNOPAUSE',)
>>> '-dBATCH',
('-dBATCH',)

You need a module to issue the system commands for you (I recommend subprocess -- It's in the standard library)

Something like:

import subprocess
args = ['gswin64.exe',
        '-q',
        '-dNOPAUSE',
        '-dBATCH',
        '-r800',
        '-sDEVICE=tiffg4',
        '-sPAPERSIZE=a4',
        '-sOutputFile=%s %s' % ('C:/My Documents','C:/Users/Tanner/Desktop/1page.pdf')]
subprocess.call(args)
mgilson
  • 264,617
  • 51
  • 541
  • 636
  • WindowsError: [Error 2] The system cannot find the file specified – Blairt Jan 11 '13 at 19:04
  • @user1970919 I don't know windows, so I'm not sure I can help you with this one. Is it python that's throwing the error, or `gswin64.exe`? Maybe it can't find `gswin64.exe`? Or perhaps there is a problem with `-sOutputFile` -- That line looks very suspect to me, but I don't know what the gs command is actually doing here. – mgilson Jan 11 '13 at 19:09
  • It was actually not throwing an error at all everything is compiling fine, it is just not doing what I ask.. – Blairt Jan 11 '13 at 19:11
  • Windows error code 2 is "ERROR_FILE_NOT_FOUND". What's `lin`? @user1970919 you can always type the command that the answer generates onto the command line yourself and see what happens. – martineau Jan 11 '13 at 19:50
  • @user1970919 Do you actually have `gswin64.exe` on the `PATH`? Or is the current directory of the script the directory where `gswin64.exe` is located? (Check them with `os.environ['PATH']` and `os.getcwd()`) – millimoose Jan 11 '13 at 21:33