How to Set Page Margins in the Bold Reports JavaScript Report Viewer
To set page margins in the Bold Reports JavaScript Report Viewer, add a pageSettings.margins object to the boldReportViewer configuration and assign top, right, bottom, and leftvalues in inches. Margins apply to the print layout, so enable printMode: true or switch to the print layout to see them.
When to use this
Use this when you need to control the whitespace around report content in the JavaScript Report Viewer, rather than relying on the margins stored in the RDL (Report Definition Language) file. Setting margins in code gives you a consistent print layout across browsers and printed documents.
Step-by-Step Instructions
- Open the JavaScript initialization file where the Report Viewer is configured.
- Locate the
boldReportViewerconfiguration object. - Add a
pageSettingsproperty, and inside it add amarginsobject. - Set
top,right,bottom, andleftto numeric values. The viewer interprets these values in
inches. - Set
printMode: trueso the viewer renders the print-optimized layout and your margins are
visible. - Replace the sample
reportServiceUrlandreportPathwith your own report service URL and RDL
report path. - Save the file and reload the page.
Full Code Example
$(function () {
$("#viewer").boldReportViewer({
// Replace with your own report service URL
reportServiceUrl: "https://<your-report-service-url>/api/ReportViewer",
// Replace with the path to your own RDL report
reportPath: '~/Resources/docs/sales-order-detail.rdl',
// Enables print-optimized rendering
printMode: true,
// Customizes the page layout margins in inches
pageSettings: {
margins: {
top: 0.5,
right: 0.25,
bottom: 0.5,
left: 0.25
}
}
});
});
Note: The
reportServiceUrlandreportPathabove are samples. Replace both with the service URL and report path from your own environment before running the code.
Property Definitions
The following table describes the properties used to configure report margins:
| Property | Description |
|---|---|
pageSettings |
Defines page-level configurations such as orientation and margins |
margins |
An object within pageSettings that defines the whitespace around the report content. |
top, bottom, left, right |
Numeric values representing margin size (in inches) |
printMode |
A Boolean value. When set to true, renders the report using a print-optimized layout |
Preview
Before Setting Page Margins
By default, the report uses the margins defined in the RDL file or the viewer’s default settings.
After Setting Page Margins
After applying the pageSettings.margins property, the report layout adjusts according to the specified margin values (for example, 0.5 inches and 0.25 inches).