Post by János Juhászdo you have any idea, how I can send a txt file to the default printer in
landscape view with python on windows.
I wanted to set up just the char size and the orientation of the printout.
I've gotten a crush on wxPython, now that it's nicely documented in the
"wxPython in Action" book.
Take a look at http://wiki.wxpython.org/index.cgi/Printing for a
discussion of printing.
Here's an example on printing, copying the code from "Code Sample - Easy
Printing" on that page.
###################################
# this part copied from URL above:
from wx.html import HtmlEasyPrinting
class Printer(HtmlEasyPrinting):
def __init__(self):
HtmlEasyPrinting.__init__(self)
def GetHtmlText(self,text):
"Simple conversion of text. Use a more powerful version"
html_text = text.replace('\n\n','<P>')
html_text = text.replace('\n', '<BR>')
return html_text
def Print(self, text, doc_name):
self.SetHeader(doc_name)
self.PrintText(self.GetHtmlText(text),doc_name)
def PreviewText(self, text, doc_name):
self.SetHeader(doc_name)
HtmlEasyPrinting.PreviewText(self, self.GetHtmlText(text))
# now, using it:
text_to_print = """
Congress shall make no law respecting an establishment of religion,
or prohibiting the free exercise thereof; or abridging the freedom
of speech, or of the press; or the right of the people peaceably to
assemble, and to petition the government for a redress of
grievances.
"""
app = wx.PySimpleApp()
p = Printer()
p.Print(text_to_print, "Amend 1")
###################################
This works, and gives you (well, the user) the option of printing
landscape.
I'm not sure how to go about specifying a font. I suspect you'll have to
go with the more heavyweight "Code Sample - `(wx)Printout` Printing"
examplefor that.