How to Set Printer Settings Programatically?
-
Hi, I am using window.print() to print the current window from Asp.net(VB) but now i want to set page size,printer name ,Orientation etc Programatically Please help me.
Darshana Pathak
u can set printer settings from the dialog box that comes when window.print is invoked... Check Properties... You cant change the default settings of the PRint dialog box from code. Its because of security issue.. But there is a way for IE users to call WScript.Shell. try out the code:
var shell;
function SetPrintProperties() {
try {
shell = new ActiveXObject("WScript.Shell");
shell.SendKeys("%fu");
window.setTimeout("javascript:SetPaperSize();", 400);
} catch (e) {
alert('Please verify that your print settings have a Landscape orientation and minimum margins.');
}
}function SetPaperSize() {
shell.sendKeys("%a{TAB}.2{TAB}0{TAB}0{TAB}0{ENTER}");
}But I dont recommend this as its browser specific and not a good practice to change settings without users consent.... :rose: Abhishek Sur
-
Hi, I am using window.print() to print the current window from Asp.net(VB) but now i want to set page size,printer name ,Orientation etc Programatically Please help me.
Darshana Pathak
JS can't do this. Might be some activex controls can do.
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
-
u can set printer settings from the dialog box that comes when window.print is invoked... Check Properties... You cant change the default settings of the PRint dialog box from code. Its because of security issue.. But there is a way for IE users to call WScript.Shell. try out the code:
var shell;
function SetPrintProperties() {
try {
shell = new ActiveXObject("WScript.Shell");
shell.SendKeys("%fu");
window.setTimeout("javascript:SetPaperSize();", 400);
} catch (e) {
alert('Please verify that your print settings have a Landscape orientation and minimum margins.');
}
}function SetPaperSize() {
shell.sendKeys("%a{TAB}.2{TAB}0{TAB}0{TAB}0{ENTER}");
}But I dont recommend this as its browser specific and not a good practice to change settings without users consent.... :rose: Abhishek Sur