Page 1 of 1
How do I change the papersize when priting
Posted: Tue Feb 20, 2007 7:07 am
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!
How do I change the papersize when priting
Posted: Tue Feb 20, 2007 9:15 am
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.
How do I change the papersize when priting
Posted: Tue Feb 20, 2007 10:32 am
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!!!
How do I change the papersize when priting
Posted: Tue Feb 20, 2007 8:02 pm
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.
How do I change the papersize when priting
Posted: Wed Feb 21, 2007 4:00 am
by EDV Gradl
It works! Thanks a lot!
How do I change the papersize when priting
Posted: Wed Feb 21, 2007 4:06 am
by Edward
Let us know if you need any help.
Thank you.