Changing Printer Trays During Print Job

空扰寡人 提交于 2021-02-08 08:12:22

问题


Is there a way to switch printer trays during a print job? I've been asked to put together a pick/pack slip program. They want the inventory pick slip to be printed on a sheet of colored paper, the pack slips to be on white paper, and they want it properly collated (pick, pack, pack, pack, pack; pick, pack, pack, pack, pack; ...).

I found some other threads on setting default trays, but didn't find anything on alternating trays during the job. Maybe I'm not searching on the right thing.

Don't know if it makes a difference, but our printer is an HP 3015n and the clients will be both XP and Win 7 Pro.


回答1:


You can try something like this you have to reference System.Drawing.dll from the projects --> Reference--> Add

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



回答2:


To my knowledge no - you have to submit 2 jobs on a queue that basically only you use.




回答3:


You can change printer tray with this code.

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


来源:https://stackoverflow.com/questions/8943312/changing-printer-trays-during-print-job

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