Page 1 of 2

How I set the paper source

Posted: Tue Nov 13, 2007 9:03 am
by EDV Gradl
When I have a printer with more then one paper sourcem how do I set which printer to use.

I tried this:

PrinterSettings MyPrinterSettings = new PrinterSettings();
MyPrinterSettings.PrinterName = "MyPrinter";
MyPrinterSettings.DefaultPageSettings.PaperSource = this.MyPrinterSettings.PaperSources[1];

How do I do it right ?

How I set the paper source

Posted: Tue Nov 13, 2007 10:12 am
by ChristianH
Did you forward your printersettings when printing report ?

this.report.Print(myPrinterSettings);

How I set the paper source

Posted: Tue Nov 13, 2007 10:52 am
by EDV Gradl
Yes, but regardless of the value of in [] it always prints in the first tray.

Marco

How I set the paper source

Posted: Tue Nov 13, 2007 12:18 pm
by Brendan
EDV wrote:When I have a printer with more then one paper sourcem how do I set which printer to use.

I tried this:

PrinterSettings MyPrinterSettings = new PrinterSettings();
MyPrinterSettings.PrinterName = "MyPrinter";
MyPrinterSettings.DefaultPageSettings.PaperSource = this.MyPrinterSettings.PaperSources[1];

How do I do it right ?
The steps look correct to me. This is pretty much what I do. I just load my paper source from a user setting instead but it's the same principle.

Only thing I can notice, and maybe it's a typo:

Code: Select all

MyPrinterSettings.DefaultPageSettings.PaperSource = this.MyPrinterSettings.PaperSources[1]; 
Are the "MyPrinterSettings" and the "this.MyPrinterSettings" two different objects?
Is 1 local to the method and the other local to the class?

What does the console print when you put this in:

Code: Select all

Console.WriteLine(MyPrinterSettings.DefaultPageSettings.PaperSource);
MyPrinterSettings.DefaultPageSettings.PaperSource = this.MyPrinterSettings.PaperSources[1]; 
Console.WriteLine(MyPrinterSettings.DefaultPageSettings.PaperSource);

How I set the paper source

Posted: Wed Nov 14, 2007 12:56 am
by EDV Gradl
Hi Brendan,

thanks for the reply.

Both the MyPrinterSettings are the same object. I just forget to delete the this when pasting from VS.

Is it important when I set the printer? I first set the printer, then load a (rendered report) and then print it.

My proble is that I can't test the tray thing, because my printer only has one :brick:

Thanks for the help so far.

Marco

How I set the paper source

Posted: Wed Nov 14, 2007 4:31 am
by ChristianH
I had success with the following method:
1. Loaded and rendered report
2. Opened a PrintDialog and passed the settings out of the dialog to myPrinterSettings

PrinterSettings myPrinterSettings = new PrinterSettings();
PrintDialog myPrintDialog = new PrintDialog();

myPrinterSettings = myPrintDialog.PrinterSettings;

3. finally printed the report using myPrinterSettings:
this.report.Print(myPrinterSettings);

How I set the paper source

Posted: Wed Nov 14, 2007 4:34 am
by Brendan
Hi,

Yeah setting the printer first is the same steps I follow.

Here's a rip of my code slightly modified:

Code: Select all

using Stimulsoft.Report;
using System.Drawing.Printing;


private void Print(string printerName, string traySource, bool autoPrint)
{
	StiReport rpt = new StiReport();
	//rpt.Load("MyReport.mrt");
	rpt.Render(false);

	//Set Printer Settings
	PrinterSettings pSettings = new PrinterSettings();
	if(printerName != String.Empty)
	{
		pSettings.PrinterName = printerName;
	}

	//Set Tray for Printing
	if(traySource != String.Empty)
	{
		foreach(PaperSource pSource in pSettings.PaperSources)
		{
			if(pSource.SourceName == traySource)
			{
				pSettings.DefaultPageSettings.PaperSource = pSource;
				break;
			}
		}
	}

	pSettings.Copies = 1;
	pSettings.FromPage = 1;
	pSettings.ToPage = rpt.RenderedPages.Count;

	rpt.Print(!autoPrint, pSettings);
}

If you are setting the PaperSource by name, there are some printers I have come across that start their Paper Source name with an empty space. I've noticed this on some HP printers. I only have 1 printer here right now with multiple trays and the first 2 paper sources are this:

Code: Select all

 Automatically Select
 Printer Auto Select
so if I set the papersource to either PaperSources[0] or PaperSources[1] I get the same tray.

I hope this helps.

p.s: I hate printers :biggrin:

How I set the paper source

Posted: Wed Nov 14, 2007 11:21 am
by Edward
Brendan wrote: p.s: I hate printers :biggrin:
Understandable and clear opinion :)

How I set the paper source

Posted: Thu Nov 15, 2007 12:52 am
by EDV Gradl
I begin to hate them as well. :brick:

Thanks for the help everyone, I think I get make it from here.

Marco

How I set the paper source

Posted: Thu Nov 29, 2007 3:56 am
by ChristianH
I thought I was knowing how to handel this issue but now I got the same problem:
I´ve a printer that is just ignoring the papersouce setting and always takes the standard tray. I can control number of copies, duplex print, ... but not the papersource !
From MS Word the printer accepts the diffrent papersources...