2

我有一个应用程序(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();
        }          
    }
}

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

当用户单击我添加的 word-ribbon-bar 上的按钮时执行代码(使用设置文件中的数据创建“printerManager”的实例)。

4

0 回答 0