Solved

C# Printing and Modifying Printer Settings

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now