Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #85728
| Return-Path | <davea@davea.name> |
|---|---|
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.034 |
| X-Spam-Evidence | '*H*': 0.93; '*S*': 0.00; 'python.': 0.02; 'output': 0.05; 'none,': 0.07; 'assuming': 0.09; 'deprecated': 0.09; 'windows,': 0.09; 'python': 0.11; 'gui': 0.12; 'windows': 0.15; '"hello': 0.16; '(also': 0.16; 'emacs,': 0.16; 'fname,': 0.16; 'hex': 0.16; 'libraries.': 0.16; 'port,': 0.16; 'qt,': 0.16; 'search:': 0.16; 'sizes,': 0.16; 'subject:printer': 0.16; 'subject:windows': 0.16; 'varies': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'file,': 0.19; 'solution.': 0.20; 'example': 0.22; 'import': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'bytes': 0.24; 'simpler': 0.24; 'text,': 0.24; "haven't": 0.24; 'appreciated': 0.26; 'equivalent': 0.26; 'asking': 0.27; 'header:In-Reply-To:1': 0.27; 'installed': 0.27; 'correct': 0.29; 'external': 0.29; "i'm": 0.30; 'go.': 0.31; 'libraries': 0.31; 'os,': 0.31; 'file': 0.32; 'text': 0.33; 'open': 0.33; 'reader': 0.33; 'copying': 0.34; 'device': 0.34; 'maybe': 0.34; 'problem.': 0.35; 'something': 0.35; 'case,': 0.35; 'but': 0.35; 'google': 0.35; 'url:org': 0.36; 'should': 0.36; 'example,': 0.37; 'so,': 0.37; 'to:addr:python- list': 0.38; 'pm,': 0.38; 'help,': 0.39; 'pdf': 0.39; 'to:addr:python.org': 0.39; 'days': 0.60; 'skip:u 10': 0.60; 'tell': 0.60; 'till': 0.61; 'simple': 0.61; "you're": 0.61; 'you.': 0.62; "you've": 0.63; 'email addr:gmail.com': 0.63; 'kind': 0.63; 'more': 0.64; 'afraid': 0.65; 'fire': 0.65; 'talking': 0.65; 'charset:windows-1252': 0.65; 'within': 0.65; 'hours': 0.66; 'received:74.208': 0.68; 'rendering': 0.68; 'url:htm': 0.73; 'drivers': 0.74; 'gotten': 0.74; 'transfer': 0.82; 'fragment': 0.84; 'increasingly': 0.84; 'received:74.208.4.194': 0.84; 'yielded': 0.84; 'acrobat': 0.91; 'device,': 0.91; 'device.': 0.93; 'laser': 0.93 |
| Date | Mon, 16 Feb 2015 22:02:33 -0500 |
| From | Dave Angel <davea@davea.name> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: Printing to printer, windows 7 |
| References | <c4b69693-c5fa-4c89-b4ab-a7a1fe898c22@googlegroups.com> |
| In-Reply-To | <c4b69693-c5fa-4c89-b4ab-a7a1fe898c22@googlegroups.com> |
| Content-Type | text/plain; charset=windows-1252; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Provags-ID | V02:K0:ymy99vNprs5GZU1M66e6PXJfM4o2CF6cgl5MznkuAcH 3iOwzKQs97xZseP4a8IXb/GcSD+ECPpx8mijDfGg13yi6x1B9l AlvkHAIV4jugPJl5DsqYNkzGxKcvcsHukpGDwQygqaOxU2Bci8 Ph6IJbgJntIYUpvZyhsluYXk7oGQTiI77OcH8foQvYHsKmR39/ CZCmaNnZVbWI4imcz3suFViddV8Hyn/1p1RESWyR7s89AGwJP2 1fgof/0UEVemifFW49b5/Db7phpFDoTd3NjDFSovI4V2oOHHel yGwI/vWF2pb9VbI3ZXi/i0kJKy09EykjXngt+hgV5fYHhIFaw= = |
| X-UI-Out-Filterresults | notjunk:1; |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.18776.1424142167.18130.python-list@python.org> (permalink) |
| Lines | 64 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1424142167 news.xs4all.nl 2868 [2001:888:2000:d::a6]:51706 |
| X-Complaints-To | abuse@xs4all.nl |
| Path | csiph.com!usenet.pasdenom.info!bete-des-vosges.org!feed.ac-versailles.fr!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
| Xref | csiph.com comp.lang.python:85728 |
Show key headers only | View raw
On 02/16/2015 09:08 PM, ken.hessel@gmail.com wrote:
> Would seem to be a simple problem. I just want to print to my printer instead of the console using Python 2.7, Windows 7. Hours of looking through FAQ's and Google haven't yielded a solution. Any suggestions appreciated --
>
It is a simple problem. All you have to do is send the correct bytes to
a file object that will transfer those bytes to the printer. It's been
a long time since I used Windows, but if I recall, you just open the
device "prn" or maybe "lpt1" and go.
For example, to print "Hello world" to an Epson MX80, on a local
parallel port, you'd do
outfile = open("lpt1", "wb")
print >> outfile, "Hello world"
(To be polite, you should use "\\dev\\lpt1", but I don't know whether
the simpler form has ever been deprecated by Windows)
Unfortunately, printers have gotten increasingly complicated since the
days of the MX80. For example on a HP laser printer, it won't start
rendering till you send a hex "0c" to it (also known as a formfeed).
You also may need to control fonts, sizes, justifications, etc., and
that varies by printer model. Some printers want Postscript. So you are
no longer talking to a printer device, but to a complex printer driver.
I'm afraid when I want to print something for the last decade or so, I
just create some form of document, and use the corresponding program to
print it for me. For simple text, I put it in a simple text file, fire
up emacs, and tell it to print.
If you've managed to get the equivalent of a "print-to-file" output for
your particular printer, then you can print it by just copying the bytes
in that file to the "prn" or "lpt1" device.
Depending on the data type you're trying to print, you may be able to
control the external program from within Python. For example, if you're
trying to print a pdf file, I got the following fragment from a google
search:
import win32api
fname="C:\\somePDF.pdf"
win32api.ShellExecute(0, "print", fname, None, ".", 0)
In this fragment, you're asking the registered pdf viewer to print it
for you. (presumably Acrobat reader or the equivalent)
If you've got a Postscript printer, perhaps the following link will
help, to print using PIL:
http://effbot.org/imagingbook/introduction.htm
The conventional way to print to an arbitrary printer, assuming it's
already installed to your OS, is to use one of the GUI libraries. If
your program is already GUI, then this is the way to go. For example,
see tkinter, wxpython, qt, ...
In this last case, the drivers and libraries abstract out the particular
kind of printer, but you need a lot more software to use it.
--
DaveA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Printing to printer, windows 7 ken.hessel@gmail.com - 2015-02-16 18:08 -0800 Re: Printing to printer, windows 7 Dave Angel <davea@davea.name> - 2015-02-16 22:02 -0500 Re: Printing to printer, windows 7 Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-02-17 00:50 -0500 Re: Printing to printer, windows 7 sjmsoft@gmail.com - 2015-02-17 12:10 -0800 Re: Printing to printer, windows 7 Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-02-17 20:41 -0500 Re: Printing to printer, windows 7 sohcahtoa82@gmail.com - 2015-02-17 17:59 -0800 Re: Printing to printer, windows 7 MRAB <python@mrabarnett.plus.com> - 2015-02-18 02:11 +0000
csiph-web