In This Topic
The Custom Preview sample demonstrates a method to view a report at client side in HTML or PDF format. Application structure consists of ASP.NET website, using which the report is streamed to the client as HTML or PDF. This sample describes custom exporting without the Pro Edition server controls or RPX handlers as well as running reports on the server. The PDF and HTML exports allow you to manually control exporting by writing a little code in ASP.NET language. Steps explained in this sample can be used for both Standard and Professional editions.
Sample Location
Visual Basic.NET
https://github.com/activereports/Samples18/tree/main/Web/CustomPreview/VB.NET
C#
https://github.com/activereports/Samples18/tree/main/Web/CustomPreview/C#
Details
When you run the sample, the Default.aspx page appears in your browser. This page provides two links to other reports that demonstrate custom PDF or HTML export options.
Clicking the Custom Exporting PDF Example option opens the Invoice report and clicking Custom Exporting HTML Example option opens NwindLabels report in the Default.aspx page.
Note: To run this sample, you must have Nwind.db downloaded from GitHub in ..\Samples18\Data\NWIND.db
The project consists of the following elements.
- Reports folder: The Reports folder contains two rpx reports - the Invoice report and the NwindLabels report.
Invoice Report
The Invoice report uses three GroupHeader sections, a Detail section and a GroupFooter section as well as a label in the PageFooter section to display data.
Note: Except for the Detail section, all sections come in header and footer pairs. Unused sections have their Height properties set to 0 and their Visible properties set to False.
ghOrderHeader section
The
DataField property of this section is set to
OrderID. This setting, in conjunction with data ordered by the OrderID field, causes the report to print all of the information for one order ID value, including all of the related details and footers, before moving on to the next order ID.
This section also contains a Picture control, a number of Label controls, and two bound TextBox controls. The TextBoxes are bound using the DataField property in the Properties window, and the date is formatted using the OutputFormat property.
ghOrderID section
The
DataField property of this section is also set to
OrderID. This allows subtotal summary functions in the related GFOrderID section to calculate properly.
This section contains a number of labels and bound text boxes, as well as two Line controls.
ghTableHeader section
This section contains only labels for the data to follow in the Detail section.
Detail section
This section contains bound TextBox controls. These TextBoxes render once for each row of data found in the current OrderID before the report moves on to the GroupFooter sections.
GFOrderID section
The
NewPage property of this section is set to
After. This causes the report to break to a new page and generate a new invoice after this section prints its subtotals.
This section contains several labels and several TextBoxes. Two of the TextBox controls use the following properties to summarize the detail data: SummaryFunc, SummaryGroup, and SummaryType. For more information, Create a Summary Report.
The Total TextBox does not use the DataField property or any of the summary properties, or even any code. To find the functionality of this TextBox, in design view, click the Script tab at the bottom of the report.
PageFooter section
This section has one simple Label control. For more information about report sections and the order in which they print, see
Section Report Layout/Structure and
Report Events.
NwindLabels Report
TheNwindLabels report only uses the Detail section to display the report data.
Note: Except for the Detail section, all sections come in header and footer pairs. Unused sections have their Height properties set to 0 and their Visible properties set to False.
Detail section
This section contains bound TextBox controls and Label controls. This section prints 30 labels per 8½ x 11 sheet.
The Detail section uses the CanGrow property set to False to maintain the label size and the ColumnCount, ColumnDirection, and ColumnSpacing properties to accommodate multiple labels in a single page.
- CustomExportHtml.aspx: This Web form is displayed by clicking the Custom Exporting HTML Example option on the Default.aspx page. In CustomExportHtml.aspx, report is outputted to the ReportOutput folder using the CustomHtmlOutput class and the exported HTML is displayed in the browser. The CustomHtmlOutput class implements the required IOutputHtml in the HTML export and saves the output results to a file with a unique name.
Note: This sample requires write permissions to the ReportOutput folder that is located in the web samples directory.
- CustomExportPdf.aspx: The Web form is displayed by clicking the Custom Exporting PDF Example option on the Default.aspx page. In CustomExportPdf.aspx, the report is exported to memory stream and then outputted in the browser.
Note: This sample requires write permissions to the ReportOutput folder that is located in the web samples directory.
- Default.aspx: This is the main Web form of the sample that shows the introductory text and links to other sample pages that demonstrate the following web features.
- Custom Exporting PDF Example - This link opens the Invoice report in the PDF Reader by exporting it to memory stream and then outputting it in the browser.
- Custom Exporting HTML Example - This link opens the NWindLabels report. This report is outputted to the ReportOutput folder by using the CustomHtmlOutput class and the exported HTML is displayed in the browser.
- Web.config: This configuration file contains the httpHandlers that allow ActiveReports to process reports on the Web. Note that you need to manually update version information here when you update your version of ActiveReports.