Printing from Letter Merge sets system default printer

This forum is for programmers who have questions about the source code.
Post Reply
richardwaite
Posts: 57
Joined: Thu Nov 15, 2007 6:51 am

Printing from Letter Merge sets system default printer

Post by richardwaite » Fri Mar 21, 2008 8:02 am

When printing a label or letter using the Letter Merge (via the toolbar), if you change the printer in the Print dialog to something other than the windows default, when the letter merge completes that newly selected printer is now the Windows default.

I traced this back to the following line of code in FormLetterMerges.cs:

Code: Select all

WrdApp.ActivePrinter=pd.PrinterSettings.PrinterName;
There is a known bug with the ActivePrinter property (detailed by Microsoft here: http://support.microsoft.com/kb/q216026/) which causes Word to set the printer specified to the system default printer. Their workaround is in VB so I've posted an equivalent workaround below in C#.

Code: Select all

object oWBasic = WrdApp.WordBasic;
object[] oWBValues = new object[] { pd.PrinterSettings.PrinterName, 1 };
String[] sWBNames = new String[] { "Printer", "DoNotSetAsSysDefault" };
oWBasic.GetType().InvokeMember("FilePrintSetup", BindingFlags.InvokeMethod, null, oWBasic, oWBValues, null, null, sWBNames);
Please note that use of the above code requires adding 'using System.Reflection;' to the top of the source file.

I've tested it on my end and it seems to do the trick. Hopefully we can get this included (maybe backported to earlier versions as well?) in the 5.6 tree.

Any input would be greatly appreciated.

Thanks,
Richard Waite
Dental IT

User avatar
jordansparks
Site Admin
Posts: 5744
Joined: Sun Jun 17, 2007 3:59 pm
Location: Salem, Oregon
Contact:

Re: Printing from Letter Merge sets system default printer

Post by jordansparks » Mon Mar 24, 2008 9:23 am

Thanks. Added it to 5.5 onward.
Jordan Sparks, DMD
http://www.opendental.com

Post Reply