开发者

Lpr -module in Python

How can you call lpr in Python?

It is not in the sys -module w开发者_运维百科hich is surprising.

I aim to use the lpr as follows shown by pseudo-code

10*i for i in range(77):              
      lpr --pages(i,i+1) file.pdf


First of, I don't understand your pseudo code. (What does 10*i for i in range(77): mean in this case?)

Generally, you use subprocess.Popen to run external commands. ActiveState recipe 511505 shows an example specifically with lpr. Basically, you can invoke lpr like this:

subprocess.Popen(['lpr', 'some_filename'])

However: Depending on your version of lpr, there may not be an option to select a subset of all pages, or this functionality may be available only for e.g. dvi files.

Edit: Since you seem to want to print selected pages of PDF files, have a look at the PDF toolkit. That software appears to provide splitting functionality. Also, make sure that directly printing PDF files is supported. You may need to convert the input to postscript first (e.g. using pdf2ps). Of course you can automate these tasks using subprocess.Popen as well.


Just call it from the commandline:

import commands

for i in range(77):
    # I'm making no assumptions about lpr command syntax here.
    cmd = "lpr --pages(%s,%s) file.pdf" % (2*i, 2*i+1)
    commands.getoutput(cmd)

Something like that.


I haven't tried it, but pycups appears to be python bindings for cups.

http://cyberelk.net/tim/software/pycups/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜