title: Printing a file and configure printer settings
body: <p>I'm trying to code a printer automation using Python on Windows, but can't get it done. </p>
  
  <p>I'm not really understanding the topic and i'm a little surprised - a "simple" way to get this done doesn't seem to exist..? There are so many APIs that allow to access common things in a nice and easy way, but printing seems to be something "special"..?</p>
  
  <p>&nbsp;</p>
  
  <p>Here is what i have and what i want to do:</p>
  
  <ul>
  <li><p>There is a PDF file. The PDF already exists, i do not want to create PDFs or any other filetype. I like to print this PDF file. One file at a time.</p></li>
  <li><p>The file could be in landscape and portrait layout. The file could have one of this sizes: A4, A3, A2, A1 and A0.</p></li>
  <li><p>I like to print the file using a normal, "physical" printer. The printer is a network device and connected using its IP. There are various network printers and i'd like to be able to use more than one of them. Some are just small A4-printers, some are big office devices (all-in-one scan, copy, print, ...) - and there are big plotters, too (up to A0 sized paper). </p></li>
  <li><p>I'd like to code: "Print this PDF file on this printer".</p></li>
  <li><p>I like to configure the printing size. I'd like to print the PDF "as it is", in its original size - but i want to be able to print big formats on small paper sizes, too. Like, the PDF itself is an A0 size, but i want to print it on A3 paper. Or the original PDF size is A2 and i want to print it on A4. </p></li>
  <li><p>I'd like to use that on Windows 7 computers (SP1, 64bit). And i'm trying to code that in python. I'm using python 2.7, as i'm using some third-party-modules that are not available in python 3. In general, every working solution that can be triggered through a python script is welcome.</p></li>
  </ul>
  
  <p>&nbsp;</p>
  
  <p>To me, that doesn't seem to be a very "complex" task to do. Doing that "by hand" is very easy and straightforward - select the document, start printing, select the printer, select the paper size - and print. </p>
  
  <p>Doing this by code seems to be rather difficult. Here is what i've come across until now.</p>
  
  <ul>
  <li><p>There are various programs that could be used for command line printing, programs like "Acrobat Reader", "Foxit Reader" or similar. While it works perfect to print using the commands those programs provide, it's not possible to access the printer settings to configure the paper size.</p></li>
  <li><p>There are special command line printing tools, but i couldn't find any useful freeware. I have tried the "VeryPDF" command line tool, but had some problems using it when it comes to paper sizes. While there is perfect support for a whole range of letter-formats and various other things, the paper sizes i need (A4 to A0) somehow aren't supported. There are presets for A4 and A3, those work. The tool has the option to use custom paper sizes by just passing the measurements (in/pt/mm) - but that didn't work as the examples show, it always prints to A4 when using this method.</p></li>
  <li><p>I've found the win32-package for python, including win32print. I don't get this thing. The API provides functions to find, add or remove printers, list a printer queue, start and stop printer jobs and so on - but no simple possibility to print a file. It seems like this API could be used to add a printer job by creating the printing data by python coding, push some text and/or graphics in something like a "file" and send that to the printer. In a format the printer already understands.</p></li>
  </ul>
  
  <p>&nbsp;</p>
  
  <p>And when using this win32print module, i can't get it to work correctly. Here is an exmple snippet i tried to use:</p>
  
  <pre><code>from win32print import *
  printer = GetDefaultPrinterW()
  handle = OpenPrinter(printer)
  info = GetPrinter(handle, 2)
  cap = DeviceCapabilities(info['pPrinterName'], info['pPortName'], DC_PAPERS)
  ClosePrinter(handle)
  </code></pre>
  
  <p>...as described here:</p>
  
  <p><a href="http://timgolden.me.uk/pywin32-docs/win32print__DeviceCapabilities_meth.html" rel="noreferrer">http://timgolden.me.uk/pywin32-docs/win32print__DeviceCapabilities_meth.html</a></p>
  
  <p>But that just returns:</p>
  
  <pre><code>NameError: name 'DC_PAPERS' is not defined
  </code></pre>
  
  <p>That happens whenever i'm trying to use a function that needs such constants passed. Not a single constant is defined on my system and i don't know why. </p>
  
  <p>But i don't know if i could use this API even when working correctly, all the usage examples are just showing how to send a text-string to a printer. That's not what i need, that's not what i want to know. </p>
  
  <p>&nbsp;</p>
  
  <p>Is there any working solution to print a file and to set the printing size in a simple and straightforward way?</p>
  
  <p>Ideas and hints are welcome!</p>