Solved

C# Printing and Modifying Printer Settings

Posted on 2013-11-04
5
1,595 Views
Last Modified: 2013-11-25
Hello Experts,

I'm working on a program that requires a user to print two documents to the same printer, but specifying each job to run from a particular paper tray (paper size issue).

The document type is a PDF, so I have not been able to use "PrintDocument" and PrintSettings, though I was able to modify PrintSettings on the fly to use the trays I wanted.

I can send the PDF directly to the print driver via a byte stream, but I seem to be unable to specify the paper source at the time of printing.  I tried modifying the PrintTicket, but it changes from "Automatic" to "Unknown" when you change the InputBin to type "Manual".

I tried cloning the printer, which actually worked, except I am still unable to change the paper source programmatically and I have concerns about the rights required to perform that task.  Users shouldn't need admin rights to run this application.

I read through a blog article (Linked Here) that goes through modifying the DEVMODE, though I've had nothing but problems even getting off the ground with that one and I'm not quite sure how he's sending the print job across once he has modified the DEVMODE.

Any thoughts?
0
Comment
Question by:piattnd
  • 3
  • 2
5 Comments
 
LVL 23

Expert Comment

by:Michael74
ID: 39623117
You can change the print tray using
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 :)

Open in new window

stackoverflow.com/questions/4808125/printing-a-pdf-automatically-to-a-specific-printer-and-tray

Michael
0
 
LVL 12

Author Comment

by:piattnd
ID: 39624498
Hey Michael,

I believe this example is using the PrintDocument class, which cannot print PDFs.  I found this class previously and was able to get it to work flawlessly, except that it cannot print PDFs.

Thanks for the suggestion though!
0
 
LVL 23

Assisted Solution

by:Michael74
Michael74 earned 100 total points
ID: 39626184
OK then, I believe you will need to use a command line pdf tool such as Ghostscript to achieve this.

http://www.ghostscript.com/
http://lvbprint.de/docu/Manual.pdf

Michael
0
 
LVL 12

Accepted Solution

by:
piattnd earned 0 total points
ID: 39663741
Hey Michael,

Sorry for the lengthy delay.  I spent a loooong time working on some solutions.

At the end of the day, I ended up using adobe itself to print to a cloned version of the printer, each clone having the necessary settings.  I'm going to delete this question, but thank you for the ideas!
0
 
LVL 12

Author Closing Comment

by:piattnd
ID: 39674128
Decided to close and award points for effort.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question