JS calls FR print method

  • Last update:  2022-01-07
  • I. Overview

    When performing report integration, it is often necessary to call FR print events through JavaScript. For example: Print without viewing, Batch Print.

    For designers whose JAR package time is before 2018-04-09, there are two ways to implement Flash and PDF client-side printing: doURLFlashPrint, doURLPDFPrint

    For designers whose JAR package time is 2018-04-09 and later, there is a way to implement new client printing: doURLPrint

    Before implementing specific examples, you need to understand the syntax of JS calling FR print methods.

    Note 1: Both the 10.0 designer and deployment package use openjdk, and flash printing cannot be started using openjdk, but Oracle/sun jdk is fine.

    Note 2: Flash printing is currently an obsolete technology. Many browsers will no longer support flash printing. It is recommended that customers use zero client or local printing.

    II. New print interface

    JS print interface: FR.doURLPrint(config), use get to pass parameters, the specific config parameters are shown in the following table:

      ParameterMeaning  
    printurl

    The application address and service of the template to be printed, such ashttp://localhost:8075/webroot/decision/view/report .

    Allow to be empty. If it is empty, the current servlet address is used. If you 

    need to cross-domain, this parameter cannot be empty.

    isPopUp

    Whether to pop up the setting window

    true: pop up

    false: do not pop up

    data

    The list of templates and their parameters to be printed, such as "[{reportlet: '1.cpt', p1:'a'}, {reportlet: '1.cpt', p1:'b'}]"

    printType

    Print type

    0: Zero client printing

    1: Local printing

    The following parameters are the parameters printed by the zero client, which only take effect when printType is 0.
    ieQuietPrint 

    IE silent printing settings

    true: silent

    false: no silence

    The following parameters are the parameters for local printing, which only take effect when printType is 1.
    printerNamePrinter name
    pageType

    Print page number type

    0: All pages

    1: current page

    2: Specify page

    pageIndex

    Page range

    Valid when pageType is 2.

    copyNumber of prints
    needSelectSheet

    Whether to print the specified Sheet page.

    true: Specify the Sheet page.

    false or empty parameters: print all Sheets.

    sheetIndex

    Sheet page, only supports positive integers or positive integer intervals.

    Example of a positive integer: 2

    Example of a positive integer interval: '7-10'

    Example:

    Create a new template, add aButtonwidget in cell A1, and add aClick event, as shown in the following figure:

    1.png

    JS code:

    var printurl="http://localhost:8075/webroot/decision/view/report";
    var reportlets ="[{reportlet: 'GettingStarted.cpt', Region: 'North China'}, {reportlet:
     'GettingStarted.cpt', Region: 'East China'}]";
    var config = {
    printUrl : printurl,
    isPopUp : true, 
    data :{ 
    reportlets: reportlets 
    },
    printType : 1, 
    ieQuietPrint : false,
    printerName : 'Microsoft Print to PDF', 
    pageType: 2, 
    pageIndex: '1-3', 
    copy: 3, 
    };
    FR.doURLPrint(config)

    Save the template, select Data Entry Preview, when you click the button, the template will be printed using local printing, as shown in the figure below:

    Note: If you cannot print normally, please refer to the precautions in the document Print Settings.

    2.png

    III. Server-side printing interface

    Server-side printing: directly call the printer connected to the server, which can solve the problem that the local PC cannot print without connecting to the printer.

    In 10.0, server-side printing can only be called via JS. If the parameter is not passed, the window will pop up; if the parameter is passed, it will print silently. The parameter has a default value, if you don't need to set it, you can skip it.

    // Pop-ups
    window.contentPane.printReportServer();
    // Silent printing
    window.contentPane.printReportServer({
         pageType: 2,  // Print page number type: 0: all pages, 1: current page, 2: specified page
         pageIndex: '1-3',  // Page number range. Valid when pageType is 2
         printerName: "" // Specify the printer
    });
    // Silent printing
    window.contentPane.printReportServer({
         pageType: 1
    });
    // Silent printing
    window.contentPane.printReportServer({})

    Example:

    Modify the JS code in the above template to:

    window.contentPane.printReportServer();

    After filling in the preview, click the button, the server-side printing (pop-up window) will be called, and the effect is as shown in the figure below:

    3.png

    IV. Old print interface

    Before calling the following method, you need to import finereport.js first, and then call it through doURLxxxxPrint().

    1. doURLxxxxPrint(printurl)

    Note: printurl is the path of the report to be printed. Printurl is passed to the server by get, and the server returns the report result to the client. The print option box and print dialog box pop up for the user to select the printing range and printer, and then print.

    Example:

    FR.doURLFlashPrint("/webroot/decision/view/report?viewlet=report.cpt")


    2. doURLxxxxPrint(printurl,isPopUp)

    Note: printurl is the path of the report to be printed.

    isPopUp Boolean value (true/false), indicating whether to print silently, true means that the print dialog box will pop up, and false means that it will not pop up.

    Example:

    FR.doURLFlashPrint("/webroot/decision/view/report?viewlet=report.cpt",true);

    Flash printing does not support silent printing, true/false has the same effect.

    FR.doURLPDFPrint("/webroot/decision/view/report?viewlet=report.cpt",true);

    PDF printing, when true, the print dialog box will pop up, and false will not pop up.


    3. doURLxxxxPrint(config)

    1) Post parameter transfer

    Note: config is parameter configuration, parameters can be passed to the server in post mode, and the data format of config is {url: url,isPopUp: isPopUp,data:{reportlets:reportlets}}.

    URL is the report path that needs to be printed, isPopUp boolean value (true/false), indicating whether to print silently, true means that the print dialog box pops up, false means no pop-up, data the report to be printed and report parameters.

    Example:

    var printurl="http://localhost:8075/webroot/decision/view/report";     
    var reportlets ="[{reportlet: '1.cpt', p1: 'a'}, {reportlet: '1.cpt', p1: 'b'}]";
    var config = {
    url : printurl,
    isPopUp : false,
    data : {
    reportlets: reportlets
    }
    };
    FR.doURLPDFPrint(config)

    Detailed examples can be viewed in Batch Print.

    2) Get parameter transfer

    Note: config is parameter configuration, parameters can be passed to the server in get mode, and the data format of config is {url: url,isPopUp: isPopUp}.

    URL is the report path that needs to be printed, isPopUp boolean value (true/false), indicating whether to print silently, true means that the print dialog box will pop up, and false means that it will not pop up.

    Example:

    var  url="http://localhost:8075/webroot/decision/view/report?viewlet=";  
    url+=document.report.cpt.value;  
    var  isPopUp = false;  
    var  config = {url : url,isPopUp : isPopUp}  
    FR.doURLPDFPrint(config)

    For detailed examples, you can view JS calling print _ print without viewing.

    Note: For the difference between post passing and get passing parameters, please see post passing parameters and get passing parameters.

    Attachment List


    Theme: Report Application
    • Helpful
    • Not helpful
    • Only read

    滑鼠選中內容,快速回饋問題

    滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。

    不再提示

    10s後關閉

    Get
    Help
    Online Support
    Professional technical support is provided to quickly help you solve problems.
    Online support is available from 9:00-12:00 and 13:30-17:30 on weekdays.
    Page Feedback
    You can provide suggestions and feedback for the current web page.
    Pre-Sales Consultation
    Business Consultation
    Business: international@fanruan.com
    Support: support@fanruan.com
    Page Feedback
    *Problem Type
    Cannot be empty
    Problem Description
    0/1000
    Cannot be empty

    Submitted successfully

    Network busy