2

I have an application (word-addin), which has a class that should print a Word-document at a selected printer & tray. It's working now, but it ignores the selected tray and always prints from manual feed. My class is the following:

class printerManager
{
    String printer_name;
    String paperSource_name;
    public printerManager(String printerName, String paperSourceName)
    {
        printer_name = printerName;
        paperSource_name = paperSourceName;

    }
    public void print()
    {
        Microsoft.Office.Interop.Word.Application wordApp = Globals.ThisAddIn.Application;
        Microsoft.Office.Interop.Word.Document wordDoc = wordApp.ActiveDocument;

        PrinterSettings printersettings = new PrinterSettings();
        printersettings.PrinterName = printer_name;
        PaperSource paperSource = new PaperSource();

        foreach (PaperSource papersource in printersettings.PaperSources)
        {
            if (papersource.SourceName.Equals(paperSource_name))
            {
                paperSource = papersource;
                break;
            }
        }
        if (!String.IsNullOrEmpty(paperSource.SourceName))
        {
            wordApp.ActivePrinter = printer_name;

            wordDoc.PageSetup.FirstPageTray = (Microsoft.Office.Interop.Word.WdPaperTray)paperSource.RawKind;
            wordDoc.PageSetup.OtherPagesTray = (Microsoft.Office.Interop.Word.WdPaperTray)paperSource.RawKind;

            wordDoc.PrintOut();
        }          
    }
}

When I debug the Code to look at the selected printer and its settings, everything is like it should be, but the printing tray isn't changing anyways.

The Code is executed when a user clicks a button at the word-ribbon-bar which I added (Creates instance of 'printerManager' with data from settings-file).

Marcel
  • 917
  • 3
  • 19
  • 48
  • I had a very similar issue a few years ago, different printers label their trays differently which is annoying. What you think it the right tray, might not be. how many trays is the app saying you can select from? and what is the actual tray number on the printer? – Simon Price Feb 04 '16 at 08:33
  • @SimonPrice I think I found a solution. The printer first has the options "Automatic","first available", "manual feed", and then numbers (1-4). If the tray for manual insertion is open, so that you can load paper in, it automatically prints at manual feed, no matter which of the first(!) options you choose. It seems to work if you only use the numbered entries. – Marcel Feb 04 '16 at 13:14
  • that sounds familiar to the issues I had. Glad you got it sorted – Simon Price Feb 04 '16 at 15:55

0 Answers0