Reputation: 9074
I have generated reports using microsoft report viewers in c#.
For making the report print in landscape view i used the code:
reportViewer1.PrinterSettings.DefaultPageSettings.Landscape = true;
This code i placed over Form Load
Event as well as reportviewer load
event as Follows :
private void BillPDF_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'dsBillPDF.totalBill' table. You can move, or remove it, as needed.
this.totalBillTableAdapter.Fill(this.dsBillPDF.totalBill,AllBill.fromDate);
reportViewer1.PrinterSettings.DefaultPageSettings.Landscape = true;
this.reportViewer1.RefreshReport();
}
private void reportViewer1_Load(object sender, EventArgs e)
{
reportViewer1.PrinterSettings.DefaultPageSettings.Landscape = true;
}
Unfortunately, this code is not working.
Is usage of reportViewer1.PrinterSettings.DefaultPageSettings.Landscape = true;
is wrong? or i have written it in wrong position.
Please help me.
Upvotes: 1
Views: 6604
Reputation: 1
If you do it like this you get the current page setting not the default ones
System.Drawing.Printing.PageSettings ps = reportViewer1.GetPageSettings();
ps.Landscape = true;
reportViewer1.SetPageSettings(ps);
Upvotes: 0
Reputation: 1
System.Drawing.Printing.PageSettings ps = new System.Drawing.Printing.PageSettings();
ps.Landscape = true;
this.reportViewer1.SetPageSettings(ps);
Work for me in VS 2010 Pro
Upvotes: 0
Reputation: 4938
At first glance your code looks fine. I found I needed to refresh the report every time I changed its orientation. From experience, I had the same problem you did with Landscaping using ReportViewer. You'll need to change the width and height settings so that the width is larger than the height.
The white portion of this screenshot is the bottom of my report. Now just right click and select "Report Properties..." below the report footer (anywhere in the blank space).
Here you can also set your orientation to Landscape (but you did it by code so that's fine). Make sure the paper size format (Letter in our case) is supported by your Printer... Some printers will not handle "Custom" formats for example.
If the width is still smaller than the height, adjust it manually and you should be able to fix your issue.
Margins are also important. You might want to play around with the margins whenever you print and / or export to PDF. ReportViewer has caused me some issues whenever I was doing this.
If all of this fails, try stretching your report like this and repeat the property procedures:
The report ruler on my .rdlc is set to 27 centimeters or so.
sReportDataSource.Name = "rptBillDataset" 'Dataset name associated to the report
sReportDataSource.Value = ds.dsBillDetail 'Dataset value
rv.rvRdlc.LocalReport.DataSources.Add(sReportDataSource)
rv.rvRdlc.PrinterSettings.DefaultPageSettings.Landscape = True
rv.rvRdlc.RefreshReport()
rv.Show()
Upvotes: 7