1

I have been trying to change my report's paper size programmatically. The goal is to make it work wherein I can configure the RDLC report's paper/page size during runtime.

As I have seen on this Link. I can configure the paper size during runtime. I have followed it and managed to change the paper size on runtime, but when the report loads. It still uses the PageSize that is indicated on the report property.

Is there something here that I have missed out. I also tried using RefreshReport(). Am I misinterpreting that PageSize and PaperSize are the same? I don't see a PageSize property under the DefaultPageSettings so I assumed that they are the same.

The screenshot below shows the changed PaperSize during runtime. I have used a message box to see if it does change.

Message Box

But the report still uses the 1100 Height by 850 Width which is specified under the PageSize property.

Page Size

Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
response.write
  • 175
  • 5
  • 23

1 Answers1

1

The Paper size which you set in Reports Properties page is the same as PageSize which you set in Properties window of the report. It determines the print page size of the report.

To set the value at run-time:

Dim pageSettings = New Printing.PageSettings()
pageSettings.PaperSize = New Printing.PaperSize("Custom", 400, 400)
Me.ReportViewer1.SetPageSettings(pageSettings)

To see the impact:

  • Click on the Print Layout button at run-time:

enter image description here

Note

  • By changing InteractiveSize.Height you can change the page size in interactive mode (default view) of viewer. For example by setting the height to 0, all the items of the report will be shown in a single page. or by setting it to 2 inch, for example, each page will show that number of rows which fits in 2 inches. You can not change it at run-time.

  • By changing the page size, you will change the page size of the report in print layout. You can change it at run-time and design-time.

  • By changing report body width, you will change the amount of space the report body needs regardless of paper size. For example if you set the page width to something smaller than report body width, there will be page breaks when printing, to print right side of report body. You cannot change it at run-time.

Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
  • 1
    nice, I will look into it more, with this, all the setting that I have pre-defined are reset to default. I will look into it more, I think, maybe I can specify other elements here like the margins. – response.write Jul 23 '18 at 15:39
  • This pretty much answered the question, I'll mark it now as an answer, I will look for way around about the margins. – response.write Jul 24 '18 at 05:31
  • If you are going to set something which could be achieved using parameters, you can define a parameter and use it in report definition. But if it's something which cannot be parametric, you can create a run-time t4 template for your report. This way you can easily pass values to the report definition. For example take a look at [this post](https://stackoverflow.com/a/40367119/3110834). – Reza Aghaei Jul 24 '18 at 05:39
  • You have your report definition as xml in the `.rdlc` file. Just copy the content into a `.tt` and add required directives at top of the file, for example the language can be VB. Then, for example for `<#= Model.BodyWidth>in`. – Reza Aghaei Jul 24 '18 at 06:01
  • I'm not sure if this is the direction that you should follow, but at ;east it's good idea to be aware of that :) – Reza Aghaei Jul 24 '18 at 06:02
  • Thanks! I have used the `pageSettings` to set the other elements that I need on the report. – response.write Jul 25 '18 at 01:35