The requested page is not available for the requested platform. You are viewing the content for Default platform.

Print and Export in Code

  • 2 min to read

This tutorial describes how to access the methods of a client-side Document Viewer instance that will print or export a report by clicking a corresponding button on the web page.

To enable printing or exporting a web report on the client side, do the following.

  1. To get started with this tutorial, open an existing reporting application or create a new one from scratch.
  2. Add a new blank report to the application and create its content.
  3. Drag-and-drop the ASPxWebDocumentViewer control from the DX.19.1: Reporting Toolbox tab onto the web page.

    drop-control-report-viewer

  4. To assign the report to the Document Viewer, click the control's smart tag and use the Report drop-down menu.

    aspx-web-doc-viewer-set-report

  5. Use the ASPxWebDocumentViewer.ClientInstanceName property to specify the name by which to address a Document Viewer on the client side to (e.g., DocumentViewer):

    HowTo_PrintWithoutToolbar_1a

  6. Drag-and-drop the ASPxButton control from the DX.19.1: Common Controls Toolbox tab onto the page.

    HowTo_PrintWithoutToolbar_1

  7. Click the button's smart tag, and in its actions list, disable the button's ASPxButton.AutoPostBack property.

    HowTo_PrintWithoutToolbar_2

  8. In the same actions list, click the Designer... link.

    HowTo_PrintWithoutToolbar_3

    In the invoked ASPxButton Designer, select the button's Click event handler and write the appropriate code into it.

    function(s, e) {
        // The following line prints the document.
        // To print a specific document page, specify its index as the method's parameter.
        DocumentViewer.Print();
    
        // The following line saves the document as a PDF file.
        // To export the document to a specific format, specify it as the method's parameter.
        // The following formats are currently supported: 
        // 'csv', 'html', 'image', 'mht', 'pdf', 'rtf', 'txt', 'xls', and 'xlsx'.
        DocumentViewer.ExportTo();
    }
    

    This code addresses the ASPxClientWebDocumentViewer by its client-side name and invokes its ASPxClientWebDocumentViewer.Print and ASPxClientWebDocumentViewer.ExportTo methods.

    Note

    To print a report, the Document Viewer first converts it to PDF, which requires that the web browser supports PDF printing. Otherwise, an attempt to print a report will instruct the web browser to download and open the corresponding PDF. This will execute an embedded script displaying a prompt to install a third-party browser extension on accepting its license agreement.

Run the application and click the button displayed on the web page to perform the specified actions.

See Also