Send grid to printer

I have a few grids which I want to print together, but I’m unable to send even a single grid to the printer. I’ve been searching for a way to send some grid to printer, I’ve found three ways of sending data to the printer, the first one is the one in the Demo, where we have a “ScrolledWindow” where we can paint and we send that to the printer, but I really haven’t found a way to work the examples out of the Demo itself -.-’

The way is much more simple:

import wx
import wx.html

class Application(wx.Frame):
def init(self):
wx.Frame.init(self, None, -1, ‘’)

    print_button  = wx.Button(self, -1, "Sample print")
    print_button.Bind(wx.EVT_BUTTON, self.print_button)
   
    mainSizer = wx.BoxSizer(wx.VERTICAL)
         
    self.SetSizer(mainSizer)
    mainSizer.Fit(self)
    mainSizer.SetSizeHints(self)

def print_button(self, event):
    self.print_order(order_html=u'<html><title></title><body>hello</body></html>')
   
   
def print_order(self, order_html):

    printout = wx.html.HtmlPrintout("Printer")
    printout.SetHtmlText(order_html)
    printout.SetMargins(10, 10, 10, 10)
   
    printData = wx.PrintData()
    format = wx.PAPER_A4
   
    printData.SetPaperId(format)
   
    printDialogData = wx.PrintDialogData()
   
    printDialogData.SetPrintData(printData)
    printDialogData.SetAllPages(True)
   
    numcopies = 1
   
    printDialogData.SetNoCopies(numcopies)
               
    printer = wx.Printer(printDialogData)
    printed = printer.Print(None, printout, False)                          

if name == “main”:
app = wx.PySimpleApp()

myapp = Application()
myapp.Show()
app.MainLoop()

I can substitute order_html by any string I want but I can’t put a grid there. The only way left is write the Grid on a file, and send that file to a printer, but I think that is a bit of an overkill…There should be an easier way to send a simple grid to print, but I can’t seem to find any example of it.

Thanks for the help.

Hello Marcos,

i’ve attached a script to print a grid. I’ve found it a long time ago, but can’t remember where. Maybe it’s of help for you.

printout.py (39.9 KB)

···

Am Mittwoch, 14. September 2016 12:56:57 UTC+2 schrieb Marcos del Amo:

I have a few grids which I want to print together, but I’m unable to send even a single grid to the printer. I’ve been searching for a way to send some grid to printer, I’ve found three ways of sending data to the printer, the first one is the one in the Demo, where we have a “ScrolledWindow” where we can paint and we send that to the printer, but I really haven’t found a way to work the examples out of the Demo itself -.-’

The way is much more simple:

import wx
import wx.html

class Application(wx.Frame):
def init(self):
wx.Frame.init(self, None, -1, ‘’)

    print_button  = wx.Button(self, -1, "Sample print")
    print_button.Bind(wx.EVT_BUTTON, self.print_button)
   
    mainSizer = wx.BoxSizer(wx.VERTICAL)
         
    self.SetSizer(mainSizer)
    mainSizer.Fit(self)
    mainSizer.SetSizeHints(self)

def print_button(self, event):
    self.print_order(order_html=u'<html><title></title><body>hello</body></html>')
   
   
def print_order(self, order_html):

    printout = wx.html.HtmlPrintout("Printer")
    printout.SetHtmlText(order_html)
    printout.SetMargins(10, 10, 10, 10)
   
    printData = wx.PrintData()
    format = wx.PAPER_A4
   
    printData.SetPaperId(format)
   
    printDialogData = wx.PrintDialogData()
   
    printDialogData.SetPrintData(printData)
    printDialogData.SetAllPages(True)
   
    numcopies = 1
   
    printDialogData.SetNoCopies(numcopies)
               
    printer = wx.Printer(printDialogData)
    printed = printer.Print(None, printout, False)                          

if name == “main”:
app = wx.PySimpleApp()

myapp = Application()
myapp.Show()
app.MainLoop()

I can substitute order_html by any string I want but I can’t put a grid there. The only way left is write the Grid on a file, and send that file to a printer, but I think that is a bit of an overkill…There should be an easier way to send a simple grid to print, but I can’t seem to find any example of it.

Thanks for the help.

Thanks a lot that’s exactly what I needed. I had the printout.py already but didn’t know how to make it print in a grid like manner.

···

El domingo, 18 de septiembre de 2016, 12:33:30 (UTC+2), Torsten escribió:

Hello Marcos,

i’ve attached a script to print a grid. I’ve found it a long time ago, but can’t remember where. Maybe it’s of help for you.

Am Mittwoch, 14. September 2016 12:56:57 UTC+2 schrieb Marcos del Amo:

I have a few grids which I want to print together, but I’m unable to send even a single grid to the printer. I’ve been searching for a way to send some grid to printer, I’ve found three ways of sending data to the printer, the first one is the one in the Demo, where we have a “ScrolledWindow” where we can paint and we send that to the printer, but I really haven’t found a way to work the examples out of the Demo itself -.-’

The way is much more simple:

import wx
import wx.html

class Application(wx.Frame):
def init(self):
wx.Frame.init(self, None, -1, ‘’)

    print_button  = wx.Button(self, -1, "Sample print")
    print_button.Bind(wx.EVT_BUTTON, self.print_button)
   
    mainSizer = wx.BoxSizer(wx.VERTICAL)
         
    self.SetSizer(mainSizer)
    mainSizer.Fit(self)
    mainSizer.SetSizeHints(self)

def print_button(self, event):
    self.print_order(order_html=u'<html><title></title><body>hello</body></html>')
   
   
def print_order(self, order_html):

    printout = wx.html.HtmlPrintout("Printer")
    printout.SetHtmlText(order_html)
    printout.SetMargins(10, 10, 10, 10)
   
    printData = wx.PrintData()
    format = wx.PAPER_A4
   
    printData.SetPaperId(format)
   
    printDialogData = wx.PrintDialogData()
   
    printDialogData.SetPrintData(printData)
    printDialogData.SetAllPages(True)
   
    numcopies = 1
   
    printDialogData.SetNoCopies(numcopies)
               
    printer = wx.Printer(printDialogData)
    printed = printer.Print(None, printout, False)                          

if name == “main”:
app = wx.PySimpleApp()

myapp = Application()
myapp.Show()
app.MainLoop()

I can substitute order_html by any string I want but I can’t put a grid there. The only way left is write the Grid on a file, and send that file to a printer, but I think that is a bit of an overkill…There should be an easier way to send a simple grid to print, but I can’t seem to find any example of it.

Thanks for the help.