How do I change the papersize when priting

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

How do I change the papersize when priting

Post by EDV Gradl »

Hi Team from Stimulsoft, I like to set the papersize at runtime.

How do i do that?

I use this code (C#):

PrinterSettings MyPrinterSettings = new PrinterSettings();
MyPrinterSettings.Printername = "MyPrinter";
MyPrinterSettings.DefaultPageSettings.PaperSize = MyPrinterSettings.PaperSizes[1];

MyReport.Print(false, this.MyPrinterSettings);

MyReport is of type StiReport and both the printer and the paper size exist.
But somehow the size is not changed, it will always print on the standard size (the one set in the driver).

What do I do wrong?

Thanks a lot!
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

How do I change the papersize when priting

Post by Edward »

To change predefault papersize for the printer please change the following line in your code:

Code: Select all

MyPrinterSettings.DefaultPageSettings.PaperSize = MyPrinterSettings.PaperSizes[1];
to

Code: Select all

StiPrintProvider.PaperSizeForUsing = MyPrinterSettings.PaperSizes[1];
This static property sets the default paper size of the report page.

This occurs in the following method of the StiPrintProvider class:

Code: Select all

		private object GetPaperSize(StiPage page, System.Drawing.Printing.QueryPageSettingsEventArgs e)
		{
			if (PaperSizeForUsing != null)return PaperSizeForUsing;

			int pageWidth = (int)Math.Round(page.Unit.ConvertToHInches(page.PageWidth), 0);
			int pageHeight = (int)Math.Round(page.Unit.ConvertToHInches(page.PageHeight), 0);
			
			foreach (PaperSize ps in e.PageSettings.PrinterSettings.PaperSizes)
			{
				if ((ps.Width == pageWidth && ps.Height == pageHeight)||
					(ps.Height == pageWidth && ps.Width == pageHeight))return ps;
			}
			return null;
		}
As you can see you also may set a page width and a page height manually. Please notice then these properties of the StiPage object you have to set in the hundredth of inches units.

Thank you.
EDV Gradl
Posts: 228
Joined: Sat Jun 17, 2006 9:50 am
Location: Germany

How do I change the papersize when priting

Post by EDV Gradl »

Hi Edward,

thanks for the fast reply, I will test it at once.

Two more questions:

a) What happens if GetPaperSize return null. What Paper Size is then used?

b) How do I override the GetPaperSize event to set my own sizes? GetPaperSize is private ans therefore can't be overwritten.

Thanks a lot!!!
Vital
Posts: 1278
Joined: Fri Jun 09, 2006 4:04 am

How do I change the papersize when priting

Post by Vital »

a) What happens if GetPaperSize return null. What Paper Size is then used?
In this case PaperSize is not used.
b) How do I override the GetPaperSize event to set my own sizes? GetPaperSize is private ans therefore can't be overwritten.
We have added static event StiPrintProvider.QueryPageSettings. It will be available in build from 21 Feb.

Thank you.
EDV Gradl
Posts: 228
Joined: Sat Jun 17, 2006 9:50 am
Location: Germany

How do I change the papersize when priting

Post by EDV Gradl »

It works! Thanks a lot!
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

How do I change the papersize when priting

Post by Edward »

Let us know if you need any help.

Thank you.
Post Reply