选定的打印机托盘不打印Word文档

时间:2016-02-04 08:15:23

标签: c# winforms visual-studio-2015 word-2013

我有一个应用程序(word-addin),它有一个应该在选定的打印机上打印Word文档的类。托盘。它现在正在工作,但它会忽略所选的托盘并始终从手动进纸打印。我的课程如下:

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();
        }          
    }
}

当我调试代码以查看所选的打印机及其设置时,一切都应该是这样,但打印托盘无论如何都不会改变。

当用户点击我添加的单词功能区栏上的按钮时执行代码(使用设置文件中的数据创建' printerManager'的实例)。

0 个答案:

没有答案