twal
twal

Reputation: 7039

Printing A PDF Automatically to a specific printer and tray

I have a C# application that When the user clicks Print the application creates a PDF in memorystream using ITextSharp. I need to print this PDF automatically to a specific printer and tray. I have searched for this but all i can find is using javascript, but it doesn't print to a specific tray. Does anyone have an examples of doing this? Thank you.

Upvotes: 2

Views: 14545

Answers (3)

Walter
Walter

Reputation: 83

in the past I spent a lot of time searching the web for solutions to print pdf files to specific printer trays.

My requirement was: collect several pdf files from server directory and send each file to a different printer tray in a loop.

So I have tested a lot of 3rd party tools (trials) and best practices found in web. Generally all theese tools can be divide into two classifications: a) send pdf files to printer in a direct way (silent in UI) or b) open pdf files in UI using a built-in pdf previewer working with .Net-PrintDocument.

The only solution that fix my requirement was PDFPrint from veryPdf (drawback: it´s not priceless, but my company bought it). All the other tools and solutions didn´t work reliable, that means: calling their print-routines with parameter e.g. id = 258 (defines tray 2; getting from installed printer) but printing the pdf file in tray 3 or pdf was opened in print previewer (UI) with lost images or totally blank content and so on..

Hope that helps a little bit.

Upvotes: 3

Antonio Suarez
Antonio Suarez

Reputation: 29

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

Upvotes: 3

Remy
Remy

Reputation: 12703

There is a tool called pdfprint:

http://www.verypdf.com/pdfprint/index.html

And here they discuss some solutions:

http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/da99765f-2706-4bb6-aa0e-b90730294cb4

Upvotes: 1

Related Questions