Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
935 views
in Technique[技术] by (71.8m points)

windows - Print PDF document with python's win32print module?

I'm trying to print a PDF document with the win32print module. Apparently this module can only accept PCL or raw text. Is that correct?

If so, is there a module available to convert a PDF document into PCL?

I contemplated using ShellExecute; however, this is not an option since it only allows printing to the default printer. I need to print to a variety of printers on servers across various networks.

Thanks for your help, Pete

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I ended up using Ghostscript to accomplish this task. There is a command line tool that relies on Ghostscript called gsprint.

You don't even need Acrobat installed to print PDFs in this fashion which is quite nice.

Here is an example:

on the command line:

gsprint -printer \serverprinter "test.pdf"

from python:

win32api.ShellExecute(0, 'open', 'gsprint.exe', '-printer "\\' + self.server + '\' + self.printer_name + '" ' + file, '.', 0)

Note that I've added to my PATH variable in these examples, so I don't have to include the entire path when calling the executable.

There is one downside, however. The code is licensed under the GPL, so it's no very useful in commercial software.

Hope this helps someone, Pete


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...