问题
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