How I set the paper source

Stimulsoft Reports.NET discussion
EDV Gradl
Posts: 228
Joined: Sat Jun 17, 2006 9:50 am
Location: Germany

How I set the paper source

Post 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 ?
ChristianH
Posts: 43
Joined: Fri May 25, 2007 2:54 am
Location: Austria

How I set the paper source

Post by ChristianH »

Did you forward your printersettings when printing report ?

this.report.Print(myPrinterSettings);
EDV Gradl
Posts: 228
Joined: Sat Jun 17, 2006 9:50 am
Location: Germany

How I set the paper source

Post by EDV Gradl »

Yes, but regardless of the value of in [] it always prints in the first tray.

Marco
Brendan
Posts: 309
Joined: Sun Jul 16, 2006 12:42 pm
Location: Ireland

How I set the paper source

Post 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);
EDV Gradl
Posts: 228
Joined: Sat Jun 17, 2006 9:50 am
Location: Germany

How I set the paper source

Post 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
ChristianH
Posts: 43
Joined: Fri May 25, 2007 2:54 am
Location: Austria

How I set the paper source

Post 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);
Brendan
Posts: 309
Joined: Sun Jul 16, 2006 12:42 pm
Location: Ireland

How I set the paper source

Post 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:
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

How I set the paper source

Post by Edward »

Brendan wrote: p.s: I hate printers :biggrin:
Understandable and clear opinion :)
EDV Gradl
Posts: 228
Joined: Sat Jun 17, 2006 9:50 am
Location: Germany

How I set the paper source

Post 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
ChristianH
Posts: 43
Joined: Fri May 25, 2007 2:54 am
Location: Austria

How I set the paper source

Post 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...
Post Reply