HTML print preview not true to print

I'm printing a mundane form written in simple HTML using this:

       f = open("indivagree.html", 'r')
       htmlText = f.read()
       f.close()
       printout = wx.html.HtmlPrintout()
       printout.SetHtmlText(htmlText)
       printout.SetMargins(12, 12) # Top, bottom
       data = wx.PrintDialogData()
       data.GetPrintData().SetPaperId(wx.PAPER_LETTER)
       data.SetAllPages(True)
       preview = wx.PrintPreview(printout, printout, data)
       pvframe = wx.PreviewFrame(preview, self.frame,
                                 "Individual Agreement Form", size=(750,500))
       pvframe.Initialize()
       pvframe.Show()

The print preview shows fine and looks good. But what gets printed is quite a bit different. Mainly the printed version is much shorter (i.e. the preview looks like it takes slightly more than a page, but the print version is much less than a page). But once I've printed it from the preview window, the preview version now agrees with what was printed.

Its is as if something isn't at first reading the right print setup or font metrics or something until it actually hits the printer.

Any thoughts?

Thanks,
Michael

Michael Hipp wrote:

I'm printing a mundane form written in simple HTML using this:

      f = open("indivagree.html", 'r')
      htmlText = f.read()
      f.close()
      printout = wx.html.HtmlPrintout()
      printout.SetHtmlText(htmlText)
      printout.SetMargins(12, 12) # Top, bottom
      data = wx.PrintDialogData()
      data.GetPrintData().SetPaperId(wx.PAPER_LETTER)
      data.SetAllPages(True)
      preview = wx.PrintPreview(printout, printout, data)
      pvframe = wx.PreviewFrame(preview, self.frame,
                                "Individual Agreement Form", size=(750,500))
      pvframe.Initialize()
      pvframe.Show()

The print preview shows fine and looks good. But what gets printed is quite a bit different. Mainly the printed version is much shorter (i.e. the preview looks like it takes slightly more than a page, but the print version is much less than a page). But once I've printed it from the preview window, the preview version now agrees with what was printed.

Its is as if something isn't at first reading the right print setup or font metrics or something until it actually hits the printer.

Any thoughts?

This might be related to the other problem. The printout object is getting scaled for the screen, and then reused for the printer, where it gets scaled again. Or something like that.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin, thanks. But it doesn't seem to have helped. I changed my code to create two entirely separate HtmlPrintout objects but the printed page is still noticeably different than the preview. My code snippet:

       f = open("indivagree.html", 'r')
       htmlText = f.read()
       f.close()
       data = wx.PrintDialogData()
       data.GetPrintData().SetPaperId(wx.PAPER_LETTER)
       data.SetAllPages(True)
       printout = wx.html.HtmlPrintout()
       printout.SetHtmlText(htmlText)
       po = wx.html.HtmlPrintout()
       po.SetHtmlText(htmlText)
       preview = wx.PyPrintPreview(printout, po, data)
       pvframe = wx.PyPreviewFrame(preview, self.frame,
                                   "Individual Agreement Form",
                                   size=(750,500))
       pvframe.Initialize()
       pvframe.Show()

I tried specifying the margins and fonts explicitly but no change.

I have a *lot* of print forms to add to this application and I'm desperate to not have to draw them bit-by-bit using DCs. Anything else I can try?

Thanks,
Michael

Robin Dunn wrote:

···

Michael Hipp wrote:

I'm printing a mundane form written in simple HTML using this:

      f = open("indivagree.html", 'r')
      htmlText = f.read()
      f.close()
      printout = wx.html.HtmlPrintout()
      printout.SetHtmlText(htmlText)
      printout.SetMargins(12, 12) # Top, bottom
      data = wx.PrintDialogData()
      data.GetPrintData().SetPaperId(wx.PAPER_LETTER)
      data.SetAllPages(True)
      preview = wx.PrintPreview(printout, printout, data)
      pvframe = wx.PreviewFrame(preview, self.frame,
                                "Individual Agreement Form", size=(750,500))
      pvframe.Initialize()
      pvframe.Show()

The print preview shows fine and looks good. But what gets printed is quite a bit different. Mainly the printed version is much shorter (i.e. the preview looks like it takes slightly more than a page, but the print version is much less than a page). But once I've printed it from the preview window, the preview version now agrees with what was printed.

This might be related to the other problem. The printout object is getting scaled for the screen, and then reused for the printer, where it gets scaled again. Or something like that.

Michael Hipp wrote:

Robin, thanks. But it doesn't seem to have helped. I changed my code to create two entirely separate HtmlPrintout objects but the printed page is still noticeably different than the preview. My code snippet:

      f = open("indivagree.html", 'r')
      htmlText = f.read()
      f.close()
      data = wx.PrintDialogData()
      data.GetPrintData().SetPaperId(wx.PAPER_LETTER)
      data.SetAllPages(True)
      printout = wx.html.HtmlPrintout()
      printout.SetHtmlText(htmlText)
      po = wx.html.HtmlPrintout()
      po.SetHtmlText(htmlText)
      preview = wx.PyPrintPreview(printout, po, data)
      pvframe = wx.PyPreviewFrame(preview, self.frame,
                                  "Individual Agreement Form",
                                  size=(750,500))
      pvframe.Initialize()
      pvframe.Show()

I tried specifying the margins and fonts explicitly but no change.

I have a *lot* of print forms to add to this application and I'm desperate to not have to draw them bit-by-bit using DCs. Anything else I can try?

Not that I can think of, the wxHtmlEasyPrinting code is doing essentially the same thing. You may want to ask about this on wx-users and/or enter a bug report about it.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!