JS calling print _ print without viewing

  • Last update:April 26, 2021
  • I. Description

    The js printing method encapsulated in FineReport is a good resource. In the user system, there is a situation as shown in the figure below, a list of lists, for each record, there is a "print" after each record, and you can click it. The detailed report corresponding to the record is printed out.

    1.png

    The effect is as follows:

    2.gif

    II. Solution

    Call FR's printing method through JS, pass the report path and parameters to be printed, and print the report.

    III. Example 1 (Calling the FR printing method in the designer template)

    1. Template settings

    1) Sub-template

    Create a new template and add a data set ds1: SELECT * FROM IndentDetail

    Drag the field into the cell and set the template as follows:

    3.png

    Double-click cell A2 to add filter conditions, as shown below:

    4.png

    2) Master template

    Create a new template and add a data set ds1: SELECT * FROM Indent limit 10

    Drag the field into the cell and set the template as follows:

    5.png


    2. Calling the FR printing method in the designer template

    When just viewing, you can call the print event through the Hyperlink-JavaScript;

    The Pagination Preview can also call the print event through the click event of the button control, and can pass parameters. The main template settings are as follows:

    6.png

    Save the template, select thePagination Preview, and achieve the effect as shown in the description.

    Note: There is no need to import finereport.js in advance when calling the print method in the designer, because the report template will be automatically imported when it is converted into a web page.

    IV. Example 2 (Calling the FR printing method on the Web page)

    If you do not use the FR designer to make, but the user's own language, when you click "Print", you can use JS to get the parameter values that need to be passed to splice out the template path that needs to be printed, and then call the FR print method to print .

    Before calling the FR printing method on the Web page, you need to import finereport.js first, and the calling code is as follows:

    <html> 
     <head> 
     <title>FineReport Demo</title> 
     <meta http-equiv="Content-Type" content="text/html; charset=GBK" />  
    <script type="text/javascript" src="/webroot/decision/view/report?op=emb&resource=finereport.js"></script>  
    <link rel="stylesheet" type="text/css" href="/webroot/decision/view/report?op=emb&resource=finereport.css"/>  
     <script type='text/javascript'> 
     function doPrint(){   
     
     
        var printurl="http://localhost:8075/webroot/decision/view/report";
    var reportlets ="[{reportlet: "+document.report.cpt.value+"}]";
    var config = {
    printUrl : printurl,
    isPopUp : true
    data :{ 
    reportlets: reportlets
    },
    printType : 1,
    printerName : 'Microsoft Print to PDF',
    pageType: 2,
    pageIndex: '1-3',
    copy: 3,
    };
    FR.doURLPrint(config);
    }   
     
    </script> 
     </head> 
     <body> 
     <form name="report"> 
     <input id="cpt" type="checkbox" value="GettingStarted.cpt" />GettingStarted.cpt<br> 
     </form> 
     <input type=button name=doprint onclick=doPrint() value='doPrint'></input> 
     </body> 
     </html>
    Show Code

    Note: The above are all local printing used. If you want to use other printing methods, you can view the JS calls FR print method, and the usage is similar.

    The completed HTML page is saved in %FR_HOME%\webapps\webroot\help\page_demo\immeprint.html

    Open the built-in server, enter http://localhost:8075/webroot/help/page_demo/cusprint_batch.html in the browser, select the check box, and click the doprint button to print.

    V. Template download

    Please refer to the completed template:

    %FR_HOME%\webapps\webroot\WEB-INF\reportlets\doc-EN\ReportApplication\FeaturesApplication\Parameter transfer printing_main-template.cpt

    %FR_HOME%\webapps\webroot\WEB-INF\reportlets\doc-EN\ReportApplication\FeaturesApplication\Parameter transfer printing_sub-

    template.cpt

    Click to download the template:  

    Parameter transfer printing_main-template.cpt

    Parameter transfer printing_sub-template.cpt

    Attachment List


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

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

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

    不再提示

    9s后關閉

    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