How do I programmatically change printer settings with the WebBrowser control?

Solution 1:

The only method I've had success with is modifying the registry on the fly (and changing them back to not affect anything else).

You can find the settings you need at "Software\Microsoft\Internet Explorer\PageSetup" under CurrentUser.

To change the printer, you can use this:

using System.Management

public static bool SetDefaultPrinter(string defaultPrinter)
{
    using (ManagementObjectSearcher objectSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_Printer"))
    {
        using (ManagementObjectCollection objectCollection = objectSearcher.Get())
        {
            foreach (ManagementObject mo in objectCollection)
            {
                if (string.Compare(mo["Name"].ToString(), defaultPrinter, true) == 0)
                {
                    mo.InvokeMethod("SetDefaultPrinter", null, null);
                    return true;
                }
            }
        }
    }
    return false;
}


As for the number of copies, you can always put the WebBrowser.Print in a while loop.

Solution 2:

            string strKey = "Software\\Microsoft\\Internet Explorer\\PageSetup";
        bool bolWritable = true;

        RegistryKey oKey = Registry.CurrentUser.OpenSubKey(strKey, bolWritable);
        Console.Write(strKey);

        if (stringToPrint.Contains("Nalog%20za%20sluzbeno%20putovanje_files"))
        {
            oKey.SetValue("margin_bottom", 15);
            oKey.SetValue("margin_top", 0.19);
        }
        else
        {
            //Return onld walue
            oKey.SetValue("margin_bottom", 0.75);
            oKey.SetValue("margin_top", 0.75);
        }

Solution 3:

you need to change registry settings via code to change settings for internet explorer or the web browser control. check out the link below, it describes how to do so, also if there's more options you need to alter using the registry, then use regedit.exe to find what other keys internet explorer has.

http://support.microsoft.com/kb/236777

ps: you should note that any changes you make via your code to internet explorer's registry settings will persist on your system/user account.