0

I'm trying to persuade a VSTO Word add-in to set the printer (which will be set by defult to black-and-white) to print this document in colour prior to calling wd.ActiveDocument.PrintOut


        printerSettings = new PrinterSettings();
        try
        {
            printerSettings.PrinterName = wb.ActivePrinter;
        }
        catch
        {
        }

        var pageSettings = new PageSettings(printerSettings);

        //To Reset after printout
        var printerColourDefaultSetting = printerSettings.DefaultPageSettings.Color;
        var printColourSettings = pageSettings.Color;

        

        if (PrinterSettings.SupportsColor) //I'd hope only one of these -but neither work
        {
            PrinterSettings.DefaultPageSettings.Color = true;
            pageSettings.Color = true;
        }
        else
        {
            //doesn't support colour
        }


      object Background = true;
        object Append = false;
        object Range = PrintOutRange;
        object To = missing;
        object From = missing;
        if (PrintOutRange == WdPrintOutRange.wdPrintFromTo)
        {
            To = LastPage.ToString(CultureInfo.InvariantCulture);
            From = FirstPage.ToString(CultureInfo.InvariantCulture);
        }
        object Copies = NoCopies;
        object PrintToFile = false;
        object Collate = true;


        wb.ActiveDocument.PrintOut(ref Background, ref Append, ref Range, ref missing, ref From, ref To,
                                            ref missing,
                                            ref Copies, ref missing, ref missing, ref PrintToFile, ref Collate,
                                            ref missing, ref missing,
                                            ref missing, ref missing, ref missing, ref missing);

However, with this code both the pageSettings and DefaultPageSettings settings I've set are being ignored. Any ideas how to force this into colour for a document?

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
Andiih
  • 12,285
  • 10
  • 57
  • 88

1 Answers1

0

The Word object model doesn't provide property or method for choosing a printer. I guess the default one will be used when you call the PrintOut method.

You can use the Windows API to set the default printer:

using System.Runtime.InteropServices;
//
public static class PrinterClass
{
        [DllImport("winspool.drv", CharSet = CharSet.Auto, SetLastError = true)]
        public static extern bool SetDefaultPrinter(string Printer);
}
//
PrinterClass.SetDefaultPrinter("Paste your desired Printer Name here");

See How do I set the windows default printer in C#? for more information.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • Thanks. However I don’t need to change the printer: it’s printing to the correct device already. What I need to do is swap this particular print to colour. – Andiih Jul 01 '22 at 21:44