Reputation: 4929
Is it possible to change the orientation on the printer when using the webbrowser control? I need to change it to landscape. If I need to change the printer defaults for the printer itself that would be ok to as I would just set them back after I was done. (That's what I currently have to do with printing to a non-default printer).
I currently use this to temporarealy set the default printer, then set it back when I'm done with my print job...
private string SetDefaultPrinter(string newDefaultPrinter)
{
//Get the list of configured printers:
string strQuery = "SELECT * FROM Win32_Printer";
string currentDefault = string.Empty;
System.Management.ObjectQuery oq = new System.Management.ObjectQuery(strQuery);
System.Management.ManagementObjectSearcher query1 = new System.Management.ManagementObjectSearcher(oq);
System.Management.ManagementObjectCollection queryCollection1 = query1.Get();
System.Management.ManagementObject newDefault = null;
foreach (System.Management.ManagementObject mo in queryCollection1)
{
System.Management.PropertyDataCollection pdc = mo.Properties;
if ((bool)mo["Default"])
{
currentDefault = mo["Name"].ToString().Trim();
if (newDefaultPrinter == null || newDefaultPrinter == string.Empty)
{
//Just need to know the default name
break;
}
}
else if (mo["Name"].ToString().Trim() == newDefaultPrinter)
{
//Save this for later
newDefault = mo;
}
}
//Reset the default printer
if (newDefault != null)
{
//Execute the method
System.Management.ManagementBaseObject outParams = newDefault.InvokeMethod("SetDefaultPrinter", null, null);
}
return currentDefault;
}
Anyone know how to change the orientation?
Upvotes: 2
Views: 3998
Reputation: 116
You can do this by using IE print templates. There are not too much documentation on this, but here below is another stack-overflow post that suggests some useful links on this regards, and it actually helped me a lot:
The most useful part was suggesting to view the standard IE print template by navigating to the below URL inside IE:
res://ieframe.dll/preview.dlg
And also you can view a related JavaScript file by navigating to the below URL inside IE:
res://ieframe.dll/preview.js
Those two files helped me a lot to understand what is going on in the background, and by changing the "Printer.orientation" value inside the "preview.js" file, I could successfully change the orientation of the printed HTML document.
Upvotes: 1
Reputation: 2740
//EDIT: I was testing it wrong. The documentation referring to this registry key is for windows CE... So the correct answer is that it is not possible, as "explained" in the documentation: http://support.microsoft.com/kb/236777
A possible workaround is to rotate the whole page through css (transform:rotate(90deg)), but the relative position keeps being the old one, so for multiple pages is just a mess.
It is incredible that something so basic can't be done...
//OLD ANSWER: I was looking for the same and finally found that you really can't change the printer settings (page orientation, header, footer, margins...) directly with the webbrowser component, the only way to do it is changing the registry key to set the default behaviour of internet explorer.
For the page orientation it would be:
Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true).SetValue("PageOrientation", 2);
You should keep the old value and restore it after printing.
Upvotes: 0