HTMLViewer Print with Pagebreaks

Hey there,

I have an HTMLViewer that displays a HTML file that I create with Xojo.

In the CSS I have defined the following css:

table { page-break-after:auto; page-break-inside:avoid }

If I open the same html file in Chrome or IE, the tables are correctly formated and page breaks are inserted in order to prevent displaying a table on two pages:

However when I use the HTMLViewer.Print function I lose the cell background colors (not a real issue) but the page breaks are lost, which is a real issue:

Is there any solution for this?

What rendering engine are you using? Is it set to Native or WebKit?
Native engine for whatever reason is not always the same as whatever IE version is installed.

Does the issue go away if you switch to WebKit?

I have tried both engines, and both produce the same problem.

[quote] The big flaw in WebKit’s printing architecture right now is that page breaks are determined at a simulated “paint” time rather than during layout itself. This means that at best all you can hope to do is try to find an optimal position for a break without altering the layout of the Web document at all.[/quote] - http://www.webkit.org/projects/printing/

Try this
http://stackoverflow.com/questions/1539876/controlling-css-page-breaks-when-printing-in-webkit

Thanks Shao for the stackoverflow link.

I really believe this is a Xojo bug and not a webkit bug.

I tried wkhtmltopdf and the page-breaks are where they should be.
Opening the HTML file inside Chrome Browser and printing, the page-breaks are where they should be.

But when printing with HTMLViewer.Print, Xojo breaks the page as soon as the end of the page is reached and the CSS page breaks aren’t used correctly.

Hi Jeremie,

I’ve had same problem with HTML viewer in my desktop apps. On Windows the Webkit Engine does not work and safe cookies because of limited user security. In IE because of strnge (I would say stupid) engine behavoir. Even with installed IE11, IE7 or Ie8 is used for rendering in HTMLviewer without support for modern CSS. You can read more on this issue here.

As solution I am checking, if my app is registred for current IE rendering engine in Windows Registry using two methods Readregistry and Writeregistry. The problem is there is also a difference between 32Bit and 64Bit Windows so you have to check twice.

Here is the code in app.open event. Replace YOUREXEFILENAME.exe with your file name. My Read and Write functions are inside a class named “TheCore” I am using in different projects but of course you can put them anywhere else.

// Registry Hack fr Windows Platform damit HTML Viewer ohne Einschrnkungen luft
  #if TargetWin32
    
    dim Sys as new TheCore
    dim b as Boolean = false
    
    // 32 Bit on 64 Bit System
    if cstr(Sys.ReadRegistry("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Internet Explorer\\MAIN\\FeatureControl\\FEATURE_BROWSER_EMULATION","YOUREXEFILENAME.exe")) = ""  then
      b = Sys.WriteRegistry("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Internet Explorer\\MAIN\\FeatureControl\\FEATURE_BROWSER_EMULATION","YOUREXEFILENAME.exe",11999,1) 
    end if
    
    // 32Bit only System (or 64 Bit)
    if b=false and cstr(Sys.ReadRegistry("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Internet Explorer\\MAIN\\FeatureControl\\FEATURE_BROWSER_EMULATION","YOUREXEFILENAME.exe")) = ""  then
      b = Sys.WriteRegistry("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Internet Explorer\\MAIN\\FeatureControl\\FEATURE_BROWSER_EMULATION","YOUREXEFILENAME.exe",11999,1) 
    end if
    
  #endif

And these are the IO functions:


  function WriteRegistry(Folder As String, Key As String, NewValue as Variante, optional RegType as Integer = 0) as Boolean

  Dim myRegItem As RegistryItem
  Dim found As Boolean = true
  Dim elements(-1), path As String
  
  elements = folder.split("\")
  
  For i As Integer = 0 To Elements.Ubound
    
    try
      
      path = path + elements(i) + "\"
      myRegItem = New RegistryItem(path, True)
      
    Catch err As RegistryAccessErrorException
      
      found = False
      Exit for
      
    Finally
      
    end try
    
  Next
  
  If found and myRegItem <> Nil Then
    
    try
      
      select case RegType
        
      case 1
        
        // Verwende DWORD
        myRegItem.value(key) = NewValue.IntegerValue
        
      case else
        
        // Verwende STRING
        myRegItem.value(key) = NewValue.StringValue
        
      end select
      return true
      
    Catch err As RegistryAccessErrorException
      
      Return false
      
    Finally
      
    end try
    
  Else
    
    Return false
    
  End If
  
end function
  
function ReadRegistry(Folder As String, Key As String) as Variant

  Dim myRegItem As RegistryItem
  Dim found As Boolean = true
  Dim elements(-1), path As String
  
  try
    
    elements = folder.split("\")
    
    For i As Integer = 0 To Elements.Ubound
      
      path = path + elements(i) + "\"
      myRegItem = New RegistryItem(path, False)
      
    Next
    
  Catch err As RegistryAccessErrorException
    
    found = False
    
  Finally
    
  end try

  If found and myRegItem <> Nil Then
    
    try
      
      if myRegItem.value(key) <> nil then 
        return myRegItem.value(key)
      else
        return ""
      end if
      
    Catch err As RegistryAccessErrorException
      
      Return ""
      
    FInally
      
    end try
    
  Else
    
    Return ""
    
  End If
  
end function

Hope I could help, greetings to France!

What platform?

Thank you very much Thomas, I will try this solution.

@shao sean
For the moment I have only tested printing with my Windows App. I don’t know yet if the same problem happens on Mac.
I will test this as soon as I have some time.

http://stackoverflow.com/questions/18860923/page-break-inside-property-is-not-working-in-chrome