Search results
PDF

Print report

The Report Viewer provides print report option in the toolbar to print a copy of the report. The page setup dialog allows you to set the paper size or other page setup properties. To see print margins, click Print Layout on the toolbar.

You can set values in the Page Setup dialog box for current session only. When you close the report and reopen it, it will have the default values again. The default values of the Page Setup dialog is based on the report properties set in the design view.

View report in print mode

Print margins are displayed in the print layout only. To view report in print mode by default, set the PrintMode property to true.

@(Html.Bold().ReportViewer("viewer")
    .ReportServiceUrl("/api/ReportViewer")
    .ReportPath("~/Resources/sales-order-detail.rdl")
    .PrintMode(true)
)

By default, the Report Viewer renders report in normal layout in which the print margins are not displayed.

To open the print in a new tab of the current browser, set the printOption property to NewTab. By default, it shows the print dialog in the same page.

@(Html.Bold().ReportViewer("viewer")
    .ReportServiceUrl("/api/ReportViewer")
    .ReportPath("~/Resources/sales-order-detail.rdl")
    .PrintMode(true)
    .PrintOption(BoldReports.ReportViewerEnums.PrintOptions.NewTab)
)

The pop-up blocker should be enabled for the page to open the print view in new tab.

Set page orientation and paper size

You can specify the print page paper size and orientation at client-side to change the page setup properties by setting the PageSettings property.

The following code example illustrates how to set page orientation and paper size in the Report Viewer for client side.

@(Html.Bold().ReportViewer("viewer")
    .ReportServiceUrl("/api/ReportViewer")
    .ReportPath("~/Resources/sales-order-detail.rdl")
    .PrintMode(true)
    .PageSettings(page => page.Orientation(BoldReports.ReportViewerEnums.Orientation.Landscape).PaperSize(BoldReports.ReportViewerEnums.PaperSize.Letter))
)

Set report margin

To set margin values to the report page setup, use the Margins property and specify the value to top, right, bottom, and left.

The following code example illustrates how to set report margin in the Report Viewer for client side.

@(Html.Bold().ReportViewer("viewer")
    .ReportServiceUrl("/api/ReportViewer")
    .ReportPath("~/Resources/sales-order-detail.rdl")
    .PrintMode(true)
    .PageSettings(page => page.Margins(margin => margin.Top(0.5).Left(0.5).Bottom(0.5).Right(0.5)))
)

The values set in the margin property is considered as inches input.

Set page height and width

To set height and width values to the report page setup, use the Height and Width properties.

The following code example illustrates how to set page height and width in the Report Viewer for client side.

@(Html.Bold().ReportViewer("viewer")
    .ReportServiceUrl("/api/ReportViewer")
    .ReportPath("~/Resources/sales-order-detail.rdl")
    .PrintMode(true)
    .PageSettings(page => page.Height(11.69).Width(8.27))
)

The values set in the height and width properties are considered as inches input.

When the report has more images, the browser will send the report stream to the print dialog before the images are completely loaded. To load the print report stream with complete images, you should set the EmbedImageData property to true in OnInitReportOptions as shown in the following code.

public void OnInitReportOptions(ReportViewerOptions reportOption)
{
    reportOption.ReportModel.EmbedImageData = true;
}

Replace the following code sample in the client-side.

@(Html.Bold().ReportViewer("viewer")
    .ReportServiceUrl("/api/PrintWithImages")
    .ReportPath("~/Resources/product-details.rdl")
)

In this tutorial, the product-details.rdl report is used, and it can be downloaded from here.

External styles in report printing

While printing report, the external styles are used in the application overrides printable page style and prints output with incorrect alignments. To avoid the external script overriding, set the isStyleLoad property to false, which will print the page using only the Report Viewer styles.

@(Html.Bold().ReportViewer("viewer")
    .ReportServiceUrl("/api/PrintWithImages")
    .ReportPath("~/Resources/product-details.rdl")
    .ReportPrint("onReportPrint")
)

<script type="text/javascript">
    function onReportPrint(args) {
        args.isStyleLoad = false;
    }
</script>

Show print progress

Report Viewer provides events to show the progress information when the printing takes long time to complete.

To show print progress, follow these steps:

  1. Set the PrintProgressChangedevent in Report Viewer initialization.
  2. Implement the function and add code samples to show a custom message based on the print progress status as shown in the following code snippet.
@(Html.Bold().ReportViewer("viewer")
    .ReportServiceUrl("/api/PrintWithImages")
    .ReportPath("~/Resources/product-details.rdl")
    .PrintProgressChanged("onPrintProgressChanged")
)

<script type="text/javascript">
    function onPrintProgressChanged(args) {
        if (args.stage == "beginPrint") {
            $('#viewer').ejWaitingPopup({ showOnInit: true, cssClass: "customStyle", text: "Preparing print data.. Please wait..." });
        }
        if (args.stage == "printStarted") {
            var popupObj = $('#viewer').data('ejWaitingPopup');
            popupObj.hide();
        }
        else if (args.stage == "preparation") {
            console.log(args.stage);
            if (args.preparationStage == "dataPreparation") {
                console.log(args.preparationStage);
                console.log(args.totalPages);
                console.log(args.currentPage);
                if (args.totalPages > 1 && args.currentPage > 1) {
                    var progressPercentage = Math.floor((args.currentPage / args.totalPages) * 100);
                    if (progressPercentage > 0) {
                        var popupObj = $('#viewer').data('ejWaitingPopup');
                        popupObj.setModel({ text: "Preparing print data.." + progressPercentage + " % completed.. Please wait..." });
                    }
                }
            }
        }

        args.handled = true;
    }
</script>

Remove empty spaces in printing

The extra blank page is created when the body of your report is too wide for your page. To make the report appear on a single page, all the content within the report body must fit on the physical page, and the body width should be as the following formula.

Body Width <= Page Width - (Left Margin + Right Margin)

For more details about removing the empty pages in the report while designing, refer to the knowledge base article of report page sizing.