Solved

C# Printing and Modifying Printer Settings

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

930 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

8 Experts available now in Live!

Get 1:1 Help Now