Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

C# Printing and Modifying Printer Settings

Posted on 2013-11-04
5
Medium Priority
?
1,775 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 23

Expert Comment

by:Michael Fowler
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:Michael Fowler
Michael Fowler earned 200 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

722 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