[python-win32] Windows printing with the use of Device Context
Neil Kenig
Neil.Kenig at modahealth.com
Mon Nov 7 20:25:57 EST 2022
You may want to try https://pypi.org/project/PyMuPDF/. It's relatively easy to create a blank PDF and then insert text of a given font and size at precise locations on the page. PDF files use points (1/72nd of an inch) for both font sizes and location on a page and will print properly regardless of the printer's resolution (assuming the stock size is the same, e.g. US Letter or A4). You can then print the PDF and if the preprinted stock is loaded into the printer, you should get the desired result.
Neil Kenig
Print Software Engineer (Document Services)
-----Original Message-----
From: python-win32 <python-win32-bounces+neil.kenig=modahealth.com at python.org> On Behalf Of Tim Roberts
Sent: Monday, November 7, 2022 3:50 PM
To: python-win32 at python.org
Subject: Re: [python-win32] Windows printing with the use of Device Context
EXTERNAL MESSAGE - TREAT LINKS/FILES WITH CARE
Antoine FINET wrote:
>
> I would like to print information at the correct coordinates on a pre
> printed form.
>
> If I understood correctly my readings, the coordinates given to a
> "TextOut" Printer Device Context depend on the resolution of the
> printer. Am I right?
Yes, but the exact same thing is true of on-screen windows. You can use GetDeviceCaps(hdc, LOGPIXELSX) to get the pixels per inch resolution.
There's also a LOGPIXELSY, but unless you have a 40-year-old graphics adapter, they are the same. The DeviceCapabilities API returns a DEVMODE structure that has detailed information about the printer.
> I don't have another printer to test but my underlying question is :
> does the coordinates depend on the printer?
Absolutely, yes. Modern printers can be 300, 600, or 1200 dots per inch. Label printers can use even wilder values.
--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the python-win32
mailing list