Selected printer-tray does not print Word document

点点圈 提交于 2019-12-13 16:18:06

问题


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).

来源:https://stackoverflow.com/questions/35195769/selected-printer-tray-does-not-print-word-document

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!