Print a file and configure printer settings

I am trying to code printer automation using Python on Windows, but cannot do this.

I don’t really understand the topic, and I'm a little surprised - the "simple" way to do this does not seem to exist ..? There are so many APIs that make it easy and simple to access common things, but printing seems to be something "special" ..?

 

Here is what I have and what I want to do:

  • There is a PDF file. PDF already exists, I do not want to create PDF files or any other type of file. I like to print this PDF file. One file at a time.

  • The file can be in landscape and portrait layouts. A file can have one of these sizes: A4, A3, A2, A1 and A0.

  • I like to print the file using a regular "physical" printer. The printer is a network device and connects using its IP address. There are various network printers, and I would like to use more than one of them. Some of them are small A4 printers, some of them are large office devices (all-in-one, copying, printing, etc.), as well as large plotters (up to paper size A0).

  • I would like to write the code: "Print this PDF file on this printer."

  • . PDF " " , . , PDF A0, A3. PDF - A2, A4.

  • Windows 7 (SP1, 64 ). python. python 2.7, , python 3. , , python script, .

    /li >

 

. "" - , , , .

. .

  • , , , "Acrobat Reader", "Foxit Reader" . , , , . ​​

  • , . VeryPDF, , . , , ( A4 A0), - . A4 A3, . , (/pt/), , , A4 .

  • win32- python, win32print. . API , , , .. - . , API , python, - / "" . , .

 

win32print . exmple, :

from win32print import *
printer = GetDefaultPrinterW()
handle = OpenPrinter(printer)
info = GetPrinter(handle, 2)
cap = DeviceCapabilities(info['pPrinterName'], info['pPortName'], DC_PAPERS)
ClosePrinter(handle)

... :

http://timgolden.me.uk/pywin32-docs/win32print__DeviceCapabilities_meth.html

:

NameError: name 'DC_PAPERS' is not defined

, , . , .

, API , , . , , , .

 

- ?

!

+4
1

" - . 2014 , . JPG , .

, , .

DC_PAPERS win32con:

import win32con
x = win32con.DC_PAPERS

, . , "" , Win32API Python...

0

Source: https://habr.com/ru/post/1540790/


All Articles