ReportPreviewer vs PDF PaperSize NOT going Landscape
I'm affraid I might need to open a case for this one but I thought I would start here first. We have a WPF app that uses the ReportPreviewer2010 and we also export directly to Excel. Interesting enough we've found that when printing direct to a printer the
reports are printing fine however when we render with the ReportPreviewer or PDF the orientation is incorrect.
I noticed another thread (an old one)
http://social.msdn.microsoft.com/Forums/en-US/vsreportcontrols/thread/4b5feee8-6d44-4c0d-899c-266b15e7993c/ where the person is complaining about the same problem. And this one
http://social.msdn.microsoft.com/forums/en-US/vsreportcontrols/thread/720eb68b-05db-412a-9af9-5e292a4f8f32/ where the person seems to have figured out a solution.
Here's the code we are firing so what's the trick to finding the correct paper settings (LocalReport.GetDefaultPageSettings)?
private string GetDeviceInfo(string outputFormat, WebReportEntity entity)
{
// CM 11/25/2009 Added per Microsoft
//_reportViewer.LocalReport.GetDefaultPageSettings().PaperSize.
// CM 01/06/2010 int paperHeight = _reportViewer.LocalReport.GetDefaultPageSettings().PaperSize.Height / 100;
decimal paperHeight;
decimal paperWidth;
decimal topMargin;
decimal leftMargin;
decimal rightMargin;
decimal bottomMargin;
if (entity.IsReportServerReport)
{
paperHeight = _reportViewer.ServerReport.GetDefaultPageSettings().PaperSize.Height / 100m;
paperWidth = _reportViewer.ServerReport.GetDefaultPageSettings().PaperSize.Width / 100m;
topMargin = _reportViewer.ServerReport.GetDefaultPageSettings().Margins.Top / 100m;
leftMargin = _reportViewer.ServerReport.GetDefaultPageSettings().Margins.Left / 100m;
rightMargin = _reportViewer.ServerReport.GetDefaultPageSettings().Margins.Right / 100m;
bottomMargin = _reportViewer.ServerReport.GetDefaultPageSettings().Margins.Bottom / 100m;
}
else
{
//this seems to be the orientation PDF problem and needs MS help
paperHeight = _reportViewer.LocalReport.GetDefaultPageSettings().PaperSize.Height / 100m;
paperWidth = _reportViewer.LocalReport.GetDefaultPageSettings().PaperSize.Width / 100m;
topMargin = _reportViewer.LocalReport.GetDefaultPageSettings().Margins.Top / 100m;
leftMargin = _reportViewer.LocalReport.GetDefaultPageSettings().Margins.Left / 100m;
rightMargin = _reportViewer.LocalReport.GetDefaultPageSettings().Margins.Right / 100m;
bottomMargin = _reportViewer.LocalReport.GetDefaultPageSettings().Margins.Bottom / 100m;
}
// The DeviceInfo settings should be changed based on the reportType
// http://msdn2.microsoft.com/en-us/library/ms155397.aspx
string deviceInfo;
if (entity.Orientation == "L")
{
deviceInfo =
"<DeviceInfo>" +
" <OutputFormat>" + outputFormat + "</OutputFormat>" +
" <PageWidth>" + paperWidth.ToString() + "in</PageWidth>" +
" <PageHeight>" + paperHeight.ToString() + "in</PageHeight>" +
" <MarginTop>" + topMargin.ToString() + "in</MarginTop>" +
" <MarginLeft>" + leftMargin.ToString() + "in</MarginLeft>" +
" <MarginRight>" + rightMargin.ToString() + "in</MarginRight>" +
" <MarginBottom>" + bottomMargin.ToString() + "in</MarginBottom>" +
" <DpiX>" + 96 + "</DpiX>" +
" <DpiY>" + 96 + "</DpiY>" +
"</DeviceInfo>";
}
else
{
deviceInfo =
"<DeviceInfo>" +
" <OutputFormat>" + outputFormat + "</OutputFormat>" +
" <PageWidth>" + paperWidth.ToString() + "in</PageWidth>" +
" <PageHeight>" + paperHeight.ToString() + "in</PageHeight>" +
" <MarginTop>" + topMargin.ToString() + "in</MarginTop>" +
" <MarginLeft>" + leftMargin.ToString() + "in</MarginLeft>" +
" <MarginRight>" + rightMargin.ToString() + "in</MarginRight>" +
" <MarginBottom>" + bottomMargin.ToString() + "in</MarginBottom>" +
" <DpiX>" + 96 + "</DpiX>" +
" <DpiY>" + 96 + "</DpiY>" +
"</DeviceInfo>";
}
return deviceInfo;
}
Chris
July 9th, 2012 8:57am
Hello Chris,
Thank you to post your questions on TechNet forum.
I reviewed your code and found that the DeviceInfo settings in two branches - I consider they are for landscape and/or portrait page settings. However, I found the code is totally same. I'm not sure whether it is a typo or not. Please try to change the pageWidth
and pageHeight order in one branch to make the page in different style.
If you have any questions about this issue, please let me know.
Regards,
Edward
TechNet Subscriber Support
If you are
TechNet Subscription user and have any feedback on our support quality, please send your feedback
here.Edward Zhu
TechNet Community Support
Free Windows Admin Tool Kit Click here and download it now
July 10th, 2012 1:42am
Hi Edward,
Actually, they are the same but there is a parameter that is checking for the orientation being "landscape". We tried a crazy idea and it worked fine but sure seems strange that the ReportViewer doesn't read landscape and portrait correctly.
if (entity.Orientation == "L")
{
deviceInfo =
"<DeviceInfo>" +
" <OutputFormat>" + outputFormat + "</OutputFormat>" +
" <PageWidth>" + Math.Max(paperWidth, paperHeight).ToString() + "in</PageWidth>" +
" <PageHeight>" + Math.Min(paperWidth, paperHeight).ToString() + "in</PageHeight>" +
" <MarginTop>" + topMargin.ToString() + "in</MarginTop>" +
" <MarginLeft>" + leftMargin.ToString() + "in</MarginLeft>" +
" <MarginRight>" + rightMargin.ToString() + "in</MarginRight>" +
" <MarginBottom>" + bottomMargin.ToString() + "in</MarginBottom>" +
" <DpiX>" + 96 + "</DpiX>" +
" <DpiY>" + 96 + "</DpiY>" +
"</DeviceInfo>";
}
else
Chris
July 10th, 2012 9:24am
Hello Chris,
Thank you to share us your solution.
I suggest you can create a bug on the http://connect.microsoft.com site, so that Microsoft can check whether the issue is a bug of reportviewer 2010. If you have further questions about this issue, please
let us know.
Regards,
Edward
TechNet Subscriber Support
If you are
TechNet Subscription user and have any feedback on our support quality, please send your feedback
here.
Edward Zhu
TechNet Community Support
Free Windows Admin Tool Kit Click here and download it now
July 11th, 2012 4:00am