mgokkaya
02-18-2007, 11:44 AM
These functions let you programatically change a users Internet Explorer printing options found under IE's File | page setup menu. Specifically it changes the header, footer, and margins. This is especially useful if you are using the Web.Print action in an AMS project to print a report or other formatted document.
The CHANGEIESETTINGS accepts 6 arguments to manipulate the Header, Footer and 4 page margins.
The RESTOREIESETTINGS restores the original user specified settings.
Place this code into your Global Functions section
--***************************
-- CHANGE FOOTER, HEADER, & MARGINS
--***************************
--Changes the Header, footer, & Margin info used when printing from IE
function CHANGEIESETTINGS(Header, Footer, MarginTop, MarginBottom, MarginLeft, MarginRight)
--Get Current Registry Key Values if they exist
IEHeader = Registry.GetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "header", true);
IEFooter = Registry.GetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "footer", true);
IEMarginTop = Registry.GetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "margin_top", true);
IEMarginBottom = Registry.GetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "margin_bottom", true);
IEMarginLeft = Registry.GetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "margin_left", true);
IEMarginRight = Registry.GetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "margin_right", true);
--Set Values based on arguments of function
Registry.SetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "header", Header, REG_SZ);
Registry.SetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "footer", Footer, REG_SZ);
Registry.SetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "margin_top", MarginTop, REG_SZ);
Registry.SetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "margin_bottom", MarginBottom, REG_SZ);
Registry.SetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "margin_left", MarginLeft, REG_SZ);
Registry.SetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "margin_right", MarginRight, REG_SZ);
end
--***************************
--Restore Header, Footer, & Margins
--***************************
function RESTOREIESETTINGS()
--Restore User Header, footer, Margin values
Registry.SetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "header", IEHeader, REG_SZ);
Registry.SetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "footer", IEFooter, REG_SZ);
Registry.SetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "margin_top", IEMarginTop, REG_SZ);
Registry.SetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "margin_bottom", IEMarginBottom, REG_SZ);
Registry.SetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "margin_left", IEMarginLeft, REG_SZ);
Registry.SetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "margin_right", IEMarginRight, REG_SZ);
endHere's an example funtion call to change the headers and set margins to .5 inches
-- Change header & footer to "My Custom Header/footer" Change margins to .5 inch
CHANGEIESETTINGS("My Custom Header", "My Custom Footer", "0.50", "0.50", "0.50", "0.50")Here's the function call to restore the original header, footer, & margins
--Restore User values for Header, Footer, & Margins
RESTOREIESETTINGS()
The CHANGEIESETTINGS accepts 6 arguments to manipulate the Header, Footer and 4 page margins.
The RESTOREIESETTINGS restores the original user specified settings.
Place this code into your Global Functions section
--***************************
-- CHANGE FOOTER, HEADER, & MARGINS
--***************************
--Changes the Header, footer, & Margin info used when printing from IE
function CHANGEIESETTINGS(Header, Footer, MarginTop, MarginBottom, MarginLeft, MarginRight)
--Get Current Registry Key Values if they exist
IEHeader = Registry.GetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "header", true);
IEFooter = Registry.GetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "footer", true);
IEMarginTop = Registry.GetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "margin_top", true);
IEMarginBottom = Registry.GetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "margin_bottom", true);
IEMarginLeft = Registry.GetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "margin_left", true);
IEMarginRight = Registry.GetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "margin_right", true);
--Set Values based on arguments of function
Registry.SetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "header", Header, REG_SZ);
Registry.SetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "footer", Footer, REG_SZ);
Registry.SetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "margin_top", MarginTop, REG_SZ);
Registry.SetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "margin_bottom", MarginBottom, REG_SZ);
Registry.SetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "margin_left", MarginLeft, REG_SZ);
Registry.SetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "margin_right", MarginRight, REG_SZ);
end
--***************************
--Restore Header, Footer, & Margins
--***************************
function RESTOREIESETTINGS()
--Restore User Header, footer, Margin values
Registry.SetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "header", IEHeader, REG_SZ);
Registry.SetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "footer", IEFooter, REG_SZ);
Registry.SetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "margin_top", IEMarginTop, REG_SZ);
Registry.SetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "margin_bottom", IEMarginBottom, REG_SZ);
Registry.SetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "margin_left", IEMarginLeft, REG_SZ);
Registry.SetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "margin_right", IEMarginRight, REG_SZ);
endHere's an example funtion call to change the headers and set margins to .5 inches
-- Change header & footer to "My Custom Header/footer" Change margins to .5 inch
CHANGEIESETTINGS("My Custom Header", "My Custom Footer", "0.50", "0.50", "0.50", "0.50")Here's the function call to restore the original header, footer, & margins
--Restore User values for Header, Footer, & Margins
RESTOREIESETTINGS()