Web Browser Control

Started by Richard Kelly, November 20, 2012, 06:53:36 AM

Previous topic - Next topic

Richard Kelly

After some absence, I'm back to working on that I like best - ma FF apps. Before my break I was studying ways to handle reporting and spent some time looking at PDF libraries as that seemed a good bet. I updated my FF to the 3.61 exe and there was the web browser control.

How would the WB control handle some HTML generated files with embedded CSS for page breaks as a general report tool? It seems so straight forward to have a generic reporting form with just the WB control on it for all my reports. And best of all, I don't have to worry about printers, preview, etc - I just have to build the file and set the URL property to my file name (I hope that part is doable).

Rick

José Roca

In the same way that Internet Explorer. You build the files and then load the main page calling the Navigate2 method. In my editor, I use an instance of the WebBrowser control for print and print preview.

Richard Kelly

I build a form with the webbrowser control and the following, per your example Jose works (like all your suggestions!)


Function REPORTS_WM_CREATE ( _
                           hWndForm As Dword, _      ' handle of Form
                           ByVal UserData As Long _  ' optional user defined Long value
                           ) As Long

Local pIWebBrowser2 As IWebBrowser2

      pIWebBrowser2 = OC_GetDispatch(HWND_REPORTS_WEBBROWSERREPORT)
      pIWebBrowser2.Navigate2 ("F:\CTarget\release\HTML\CTReport.htm")

End Function


I've been reading up on further customizations.

1. Is there a way to set the paper size and control whether the default headers and footers are printed?
2. Is there a reliable way when building a report to know when a page break is needed?

Rick Kelly

José Roca

#3
All these things must be done in the html code.

You can also activate the page setup dialog with:

pIWebBrowser2.ExecWB %OLECMDID_PAGESETUP, %OLECMDEXECOPT_PROMPTUSER

Richard Kelly

Thank you Jose for the additional information. It's been a few years since I wrote any HTML code, and in 5 min or so I came up with following promising template. It's not quite right - the first cell on the second page is blank, but it gives me something to play with:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en" id="vbulletin_html">
<head><title>HTML Page Break Sample</title></head>
<body>
<!DOCTYPE html>
<style type="text/css">
@media print {
   thead {display: table-header-group;}
   tfoot {display: table-footer-group;}
   body {font-family: arial, serif ; font-size: 12pt; line-height: 120%; background: white;}

}
body {
  color : #000000;
  background : #ffffff;
  font-family : "Tahoma", "Verdana", Arial, sans-serif;
   font-size : 12pt;
}


th,
td {
padding: 4px 4px 4px 4px ;
text-align: center ;
}


th {
border-bottom: 2px solid #333333 ;
}


td {
border-bottom: 1px dotted #999999 ;
}


tfoot td {
border-bottom-width: 0px ;
border-top: 2px solid #333333 ;
padding-top: 20px ;
vertical-align: bottom;
}

</style>
<table>
   <thead>
     <tr>
       <th>AAAA</th>
       <th>BBBB</th>
       <th>CCCC</th>
     </tr>
   </thead>
  <tfoot>
     <tr>
       <td colspan="3">
       HTML Page Break Footer
      </tr>
   </tfoot>
   <tbody>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>

     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>1111</td>
       <td>1111</td>
       <td>1111</td>
    </tr>
     <tr>
       <td>2222</td>
       <td>2222</td>
       <td>2222</td>
    </tr>
   </tbody>
</table>
</body>
</html>


Rick Kelly