0

I am passing in this DeviceInfo to the report:

<DeviceInfo>
  <OutputFormat>Word</OutputFormat>
  <PageWidth>11in</PageWidth>
  <PageHeight>8.5in</PageHeight>
  <MarginTop>1in</MarginTop>
  <MarginLeft>0.5in</MarginLeft>
  <MarginRight>0.5in</MarginRight>
  <MarginBottom>1in</MarginBottom>
</DeviceInfo>

However when the report renders (as Word or PDF), the page size is 11 by 11 inches, rather than 11 by 8.5 (landscape). Why is this? How can I get the report to render with the proper size?

Here is where I render the report:

byte[] bytes = Report.Render( // Report is an instance of the Microsoft.Reporting.WebForms.LocalReport class
    reportType,
    deviceInfo, // this contains the XML above
    out mimeType,
    out encoding,
    out fileNameExtension,
    out streams,
    out warnings);
ekolis
  • 6,270
  • 12
  • 50
  • 101

2 Answers2

0

In the Report builder or Visual Studio you have also to set the Layout of the Report to Landscape so it will know how to renderLandscape Property

Rampage64
  • 158
  • 1
  • 6
  • Hmm, I'm not using a report builder or Visual Studio to define the report; rather I'm using C# code to generate the report. Do you know where this would be set? – ekolis Oct 30 '19 at 17:00
  • you are using C# code to generate the `*.rdlc` files? you could try this: `System.Drawing.Printing.PageSettings ps = new System.Drawing.Printing.PageSettings(); ps.Landscape = true; ps.PaperSize = new System.Drawing.Printing.PaperSize("A4", 827, 1170); ps.PaperSize.RawKind = (int)System.Drawing.Printing.PaperKind.A4; reportViewer.SetPageSettings(ps);` I never tried that, give it a try :) – Rampage64 Oct 30 '19 at 17:03
  • I'm not using a `ReportViewer`; the report is generated as HTML, PDF, Word, or Excel using the `Report.Render` call above. – ekolis Oct 30 '19 at 17:08
  • I'm not sure if I understand you correctly, how you create the definition file of the `rdlc` file ? - if you do not use an ReportViewer try at least to use in the code just to export the report and not to place it in the GUI – Rampage64 Oct 30 '19 at 17:15
  • The RDLC is generated using a variety of custom classes which output various RDLC XML elements. – ekolis Oct 30 '19 at 17:19
  • Well then you have to modify the xml definition I guess.. I'm not sure about the xml structure of the rdlc definition itself - you need to google that if that is possible. Good Luck – Rampage64 Oct 30 '19 at 17:37
  • Try This link: https://stackoverflow.com/questions/21455090/printing-landscape-portrait-in-rdlc-without-preview – Rampage64 Oct 30 '19 at 17:40
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/201618/discussion-between-flamur-muji-and-ekolis). – Rampage64 Oct 30 '19 at 17:40
0

It looks like the report page size was not being initialized properly, so I did so:

var page = report.Page;

page.LeftMargin = LeftMargin;
page.RightMargin = RightMargin;

page.TopMargin = TopMargin;
page.BottomMargin = BottomMargin;

// I added these next two lines
page.PageWidth = PageWidth;
page.PageHeight = PageHeight;
ekolis
  • 6,270
  • 12
  • 50
  • 101