467,880 Members | 1,110 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,880 developers. It's quick & easy.

printing Html without Header and Footer

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 :)
Nov 21 '05 #1
  • viewed: 8852
Share:
2 Replies
mmm anyone have an idea ? i m really stuck :s

thanx :)
Nov 21 '05 #2
up!
it seems that no one knows a way ...
arg ...
"LilBuh" <Li****@discussions.microsoft.com> a écrit dans le message de news:
97**********************************@microsoft.com...
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 :)

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Niyazi | last post: by
12 posts views Thread by Alex Clark | last post: by
2 posts views Thread by johnb41 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.