Printing A PDF Automatically to a specific printer and tray

13,100

Solution 1

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

Solution 2

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

Solution 3

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.

Share:
13,100
twal
Author by

twal

C# .net programmer

Updated on June 05, 2022

Comments

  • twal
    twal almost 2 years

    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.

  • twal
    twal about 13 years
    pdfprint is pricey, I really need a free solution.
  • Remy
    Remy about 13 years
    You might have troubles finding a free solution for this. You could try some of the free PDF Libraries out there and split the file and then print them to different printers with the normal acrobate command line tools. But first you have to be able to split the pdf file.
  • Walter
    Walter over 9 years
    Why are you rating me down?
  • Sivajith
    Sivajith about 9 years
    I have an issue with this.. In the foreach statement i have only autoselect, auto and manual feed option are available. Can anyone help me on this?
  • juFo
    juFo about 7 years
    Another commercial solution is called Print&Share. It can route between printers, has profile delection, can print to different paper trays and combine all.