printing Html without Header and Footer

G

Guest

hi there :)
i ve been looking for some time a way to print an html file from vb.net
i came up with this code for printing and removing the header and footer
from IE
then once the printing is done restore the original header and footer

Imports Microsoft.Win32

Private WithEvents myprocess As Process
Private OldHeader As String
Private OldFooter As String

private sub printhtml()
GetIEHeaderFooter(OldHeader, OldFooter)
SetIEHeaderFooter(" ", " ")
myprocess = New Process
myprocess.StartInfo.FileName = "temp.htm"
myprocess.StartInfo.Verb = "Print"
myprocess.StartInfo.CreateNoWindow = True
myprocess.EnableRaisingEvents = True
myprocess.Start()
end sub

Public Sub SetIEHeaderFooter(ByVal Header As String, ByVal Footer As
String)
Dim strKey As String = "Software\Microsoft\Internet
Explorer\PageSetup"
Dim oKey As RegistryKey = Registry.CurrentUser.OpenSubKey(strKey,
True)
If Not Header = vbNullString Then
oKey.SetValue("header", Header)
End If

If Not Footer = vbNullString Then
oKey.SetValue("footer", Footer)
End If
oKey.Close()
End Sub

Public Sub GetIEHeaderFooter(ByRef Header As String, ByRef Footer As
String)
Dim strKey As String = "Software\Microsoft\Internet
Explorer\PageSetup"
Dim oKey As RegistryKey = Registry.CurrentUser.OpenSubKey(strKey,
False)
Header = oKey.GetValue("header")
Footer = oKey.GetValue("footer")
oKey.Close()
End Sub

Private Sub myprocess_Exited(ByVal sender As Object, ByVal e As
System.EventArgs) Handles myprocess.Exited
SetIEHeaderFooter(OldHeader, OldFooter)
End Sub

IE is showing the printing dialog... and the process stops... before i can
press the print button so the original Header and Footer are restored and
printed ... i need to find a way to either remove the printing dialog ... or
find out when to restore the Header/footer so that it doent appear on the
printed page.

( sorry for my english ... hope i m clear enough )

thanx :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top