Solved

C# Printing and Modifying Printer Settings

Posted on 2013-11-04
5
1,716 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 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

Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

626 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