2010-05-20 169 views
1

我需要從Python腳本打印現有的PDF文件。以編程方式打印PDF文件 - 指定打印機

我需要能夠在腳本中指定打印機。它在Windows XP上運行。

任何想法我可以做什麼?

This method看起來會不同的是,我不能指定打印機工作:

win32api.ShellExecute (
    0, 
    "print", 
    filename, 
    None, 
    ".", 
    0 
) 
+0

片斷你的意思是 「不能指定打印機」,而不是 「可以指定」,是嗎? – msw 2010-05-20 23:47:10

+0

是的,我修正了這個,謝謝。 – Greg 2010-05-21 11:01:51

+0

我想你可以在[這個類似的帖子]中找到合適的答案(http://stackoverflow.com/questions/1462842/print-pdf-document-with-pythons-win32print-module) – bluish 2010-12-16 16:45:41

回答

0

請參閱本link進一步的細節

import tempfile 
import win32api 
import win32print 

filename = tempfile.mktemp (".txt") 
open (filename, "w").write ("This is a test") 
win32api.ShellExecute (
    0, 
    "print", 
    filename, 
    # 
    # If this is None, the default printer will 
    # be used anyway. 
    # 
    '/d:"%s"' % win32print.GetDefaultPrinter(), 
    ".", 
    0 
) 

這將工作請參閱提供link進一步的細節。

0

有一個未公開printto動詞,採取打印機名稱作爲參數(引號括起來,如果它包含空格)

import tempfile 
import win32api 
import win32print 

filename = tempfile.mktemp (".txt") 
open (filename, "w").write ("This is a test") 
win32api.ShellExecute (
    0, 
    "printto", 
    filename, 
    '"%s"' % win32print.GetDefaultPrinter(), 
    ".", 
    0 
) 

Ja8zyjitslink