Issue with HtmlEasyPrinting on Debian and Ubuntu
Jean-Paul Verhulst <[email protected]> Tue, 27 Feb 2018 00:16:41 -0800 (PST)
| Newsgroups | gmane.comp.python.wxpython.devel |
|---|---|
| Message-ID | <[email protected]> |
The script "htmleasyprinting.py" (see attachment) works very well with windows 10 but not with Linux. It uses "table" and "tr" tags with "bgcolor". The preview is good but the printing is unusable (see PDF in attachment). Test OK with Windows 10, wxPython 4.0.1, Python 3.6.4 Issue with Debian 9, Debian 10, Ubuntu 17.10, Raspbian Stretch - wxPython 4.0.1 GTK2 More problems with GTK3: - Preview with black background and non-visible header - Scrollbar errors if we reduce the size of the preview window (htmleasyprinting.py:3987): Gtk-WARNING **: Negative content width -9 (allocation 25, extents 17x17) while allocating gadget (node button, owner GtkButton) - Same unusable printing as with GTK2 -- You received this message because you are subscribed to the Google Groups "wxPython-dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
htmleasyprinting.py
(text/x-python, 2.6 KB)
#!/usr/bin/env python3
import wx
import wx.html
class Frame(wx.Frame):
def __init__(self, parent, size, title):
super().__init__(parent, size=size, title=title)
panel = wx.Panel(self)
self.htmlwindow = wx.html.HtmlWindow(panel)
self.preview_button = wx.Button(panel, label="Preview")
self.print_button = wx.Button(panel, label="Print")
self.ep = wx.html.HtmlEasyPrinting(
name="Test - HtmlEasyPrinting", parentWindow=self)
self.header = """\
<table cellspacing="0" cellpadding="0" width="100%"><tr>
<td width="75%" align="center"><b>@TITLE@</b></td>
<td align="right" width="25%">PAGE @PAGENUM@/@PAGESCNT@</td>
</tr></table>
"""
self.body = """\
<html><body>
<p>Table with borders</p>
<table bgcolor="grey" cellspacing="3" cellpadding="3" width="100%">
<tr bgcolor="#ffff99"><td><font color="red"><b>AAA</b></font></td><td>BBB</td><td>CCC</td></tr>
<tr bgcolor="white"><td><span style="color:green";"><b>DDD</b></span></td><td>EEE</td><td>FFF</td></tr>
</table>
<p>Table without border</p>
<table cellspacing="3" cellpadding="3" width="100%">
<tr bgcolor="#ffff99"><td><font color="red"><b>GGG</b></font></td><td>HHH</td><td>III</td></tr>
<tr><td><span style="color:green";"><b>JJJ</b></span></td><td>KKK</td><td>LLL</td></tr>
</table>
</body></html>
"""
self.htmlwindow.SetPage(self.body)
sizer = wx.BoxSizer(wx.VERTICAL)
button_sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(self.htmlwindow, 1, wx.EXPAND)
button_sizer.Add(self.preview_button, 1, wx.EXPAND)
button_sizer.Add(self.print_button, 1, wx.EXPAND)
sizer.Add(button_sizer, 0, wx.EXPAND)
panel.SetSizer(sizer)
self.SetSizeHints(200, 200)
self.Bind(wx.EVT_BUTTON, self.button)
def button(self, evt):
self.ep.SetHeader(self.header)
# pd = self.ep.GetPrintData()
# pd.SetOrientation(wx.PORTRAIT)
# pd.SetPaperId(wx.PAPER_A4)
# pd.SetColour(False)
# psd = self.ep.GetPageSetupData()
# psd.SetMarginTopLeft((10, 10))
# psd.SetMarginBottomRight((10, 10))
if evt.GetEventObject() is self.preview_button:
self.ep.PreviewText(self.body, basepath="")
else:
self.ep.PrintText(self.body, basepath="")
class App(wx.App):
def OnInit(self):
frame = Frame(
parent=None, size=(400, 300), title="HtmlEasyPrinting")
frame.Show()
self.SetTopWindow(frame)
return True
def OnExit(self):
return super().OnExit()
if __name__ == "__main__":
app = App(True)
app.MainLoop()
htmleasyprinting-win-output.pdf
(application/pdf, 18.6 KB) - not displayed
htmleasyprinting-linux-output.pdf
(application/pdf, 31.8 KB) - not displayed