Articles in this section
Category / Section

Dynamically Setting Page Height and Width in Bold Reports Writer

Published:
Updated:

In Bold Reports, you can dynamically set the page height and width in the Report Writer control according to your requirements. This flexibility is particularly useful for ensuring proper pagination and layout in exported documents. By adjusting these settings, users can maintain the intended formatting of their reports across different export formats, regardless of the output medium. This feature allows users to tailor their reports to fit various page sizes, including custom dimensions, standard A4, letter sizes, and more.

To utilize this option, please follow the steps below.

  1. First, initialize an instance of the ReportWriter class in Bold Reports. This instance will handle exporting reports with customizable settings.
BoldReports.Writer.ReportWriter writer = new BoldReports.Writer.ReportWriter(); 
  1. Use the PageSettings property to set the page height and width dynamically. These values must be specified in pixels. If your measurements are in inches, you will need to convert them to pixels:
writer.PageSettings = new PageSettings();
writer.PageSettings.PageHeight = 1587.84; // Set height in pixels
writer.PageSettings.PageWidth = 1122.24;  // Set width in pixels 

Before Export:

image.png

After Export:

image.png

You must specify the page height and width exclusively in pixels, as demonstrated in the code snippet above. If you wish to use any other measurement units, convert those values to pixels before passing them.

Since page dimensions are required in pixels, you can create a simple function to convert inches to pixels (1 inch = 96 pixels). Use the below converter function to pass dimensions in inches when needed:

public double InchToPixelConvertor(double value)
{
   return value * 96;
} 

When exporting reports, use the above conversion to dynamically set the page height and width based on inches, ensuring your report adheres to the desired format.

public IActionResult Export(string writerFormat)
{
   // Other export code here
   BoldReports.Writer.ReportWriter writer = new BoldReports.Writer.ReportWriter();
   writer.PageSettings = new PageSettings();
   writer.PageSettings.PageHeight = InchToPixelConvertor(16.54); // Example for height in inches
   writer.PageSettings.PageWidth = InchToPixelConvertor(11.69);  // Example for width in inches
   // Export logic continues...
} 

A sample application is attached here for your reference.

See Also:

Was this article useful?
Like
Dislike
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied