更换打印作业过程中的打印纸盘

3
有没有办法在打印作业期间切换打印机托盘?我被要求制作一个拣货/包装清单程序。他们希望将库存拣选单打印在一张彩色纸上,包装单打印在白纸上,并希望正确地整理(拣选,包装,包装,包装,包装;拣选,包装,包装,包装,包装;...)。
我找到了一些关于设置默认托盘的其他主题,但没有找到任何有关在作业期间交替使用托盘的内容。也许我没有搜索正确的内容。
不知道是否有区别,但我们的打印机是HP 3015n,客户端将是XP和Win 7 Pro。

abatishchev - 我看到你编辑了我的帖子。开发环境和编程语言不相关吗? - Sam
3个回答

5
你可以尝试这样做,需要在项目中引用System.Drawing.dll。具体操作为:项目--> 引用--> 添加。
//Namespace:  System.Drawing.Printing
//Assembly:  System.Drawing (in System.Drawing.dll)

PrintDocument printDoc = new PrintDocument();
PaperSize oPS = new PaperSize();
oPS.RawKind = (int)PaperKind.A4;
PaperSource oPSource = new PaperSource();
oPSource.RawKind = (int) PaperSourceKind.Upper;

printDoc.PrinterSettings = new PrinterSettings();
printDoc.PrinterSettings.PrinterName = sPrinterName;
printDoc.DefaultPageSettings.PaperSize = oPS;
printDoc.DefaultPageSettings.PaperSource = oPSource;
printDoc.PrintPage += new PrintPageEventHandler(printDoc_PrintPage);
printDoc.Print();
printDoc.Dispose();

那么,基本上我将创建数百个小型打印作业,并在作业之间更改纸张来源? - Sam
还没有机会测试并查看它是否有效,但可能有效,并且比我自己做的更进一步。由于几天内没有其他人发表评论,我将标记为答案。谢谢! - Sam
2
抱歉,我无法让这种方法在同一作业中更改托盘。我在printDoc_PrintPage中更改托盘。它似乎忽略了那个更改...有没有完全可行的实现的机会? - Phil C

0
据我所知,不行 - 你必须在一个队列上提交两个作业,而这个队列基本上只有你使用。

不确定我是否理解,请详细说明一下?谢谢。 - Sam
两个不同托盘的纸张类型名称是什么? - MethodMan
不确定您所说的“纸张类型”是什么意思?托盘1将是彩色8.5x11,托盘2将是白色8.5x11。 - Sam
1
请查看此链接:http://www.textcontrol.com/en_US/downloads/library/snippet/papersource/,这是一个更好的示例。 - MethodMan
请告诉我这是否对您有用,我很感兴趣了解。这里有很多人提出了类似的问题,也许这个网站可以成为他们所寻找的全部。 - MethodMan

-1

你可以使用这段代码更改打印机的纸盘。

string _paperSource = "TRAY 2"; // Printer Tray
string _paperName = "8x17"; // Printer paper name

//Tested code comment. The commented code was the one I tested, but when 
//I was writing the post I realized that could be done with less code.

//PaperSize pSize = new PaperSize()  //Tested code :)
//PaperSource pSource = new PaperSource(); //Tested code :)

/// Find selected paperSource and paperName.
foreach (PaperSource _pSource in printDoc.PrinterSettings.PaperSources)
{
    if (_pSource.SourceName.ToUpper() == _paperSource.ToUpper())
    {
        printDoc.DefaultPageSettings.PaperSource = _pSource;
        //pSource = _pSource; //Tested code :)
        break;
    }
}

foreach (PaperSize _pSize in printDoc.PrinterSettings.PaperSizes)
{
    if (_pSize.PaperName.ToUpper() == _paperName.ToUpper())
    {
        printDoc.DefaultPageSettings.PaperSize = _pSize;
        //pSize = _pSize; //Tested code :)
        break;
    }
}

//printDoc.DefaultPageSettings.PaperSize = pSize; //Tested code :)
//printDoc.DefaultPageSettings.PaperSource = pSource;    //Tested code :)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接