-1

我已经用尽了所有的努力,仍然对为什么这个简单的程序不会输出 tiff 文件感到困惑。它应该只提取一个 PDF 文件,将其转换为 tiff 并增强图像。无论如何,我都不是一个伟大的程序员,但这似乎并不难......我认为我的问题是我很难让 ghostscript 完全调用。我已经尝试过 (gs, gswin32c, gswin32, gswin64, gswin64c, gsoso) 仍然没有输出...这是我的 Python 脚本。


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')
4

1 回答 1

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)
于 2013-01-11T18:56:48.440 回答