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.
The effect is as follows:
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:
Double-click cell A2 to add filter conditions, as shown below:
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:
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:
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>
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: