Jump to content

Recommended Posts

Posted

Hi ,

I am getting empty PDF , First i am preparing the JRXML file from the jaspersoft studio with Json datasource , i am getting value in PDF in the Jasper studio But once i am integrating with the Our project ie (Spring Restfull+AngularJs) but i am getting empty PDF...

html page:

<div class="container-fluid"  id="table-content-wrapper">
<!-- Row start -->
  <div class="row">
    <div class="col-xs-12">
      <div class="panel panel-default">
        <div class="panel-heading clearfix">
          <i class="icon-calendar"></i>
          <h3 class="panel-title">Lead</h3>
        </div>
       
       
        <div class="panel-body table-responsive">
        
<div>
<form class="form-horizontal" role="form" name="userform" ng-submit="Download()" novalidate>
 
<md-input-container class="md-block"> <label>Company Id</label>
<input name="companyid" ng-model="user.companyid" class="form-control" id="companyid" required>
<div ng-messages="user.companyid.$error">
<div ng-message="required">This is required!</div>
</div>
</md-input-container>
 
<md-input-container class="md-block"> <label>Web Id</label>
<input type="webid" name="webid" ng-model="user.webid" class="form-control"
id="webid" />
<div ng-messages="user.webid.$error">
<div ng-message="required">This is required!</div>
</div>
</md-input-container>
        <button type="button"  class="btn btn-sm btn-success" ng-click="loadCompanies()">
<i class="glyphicon glyphicon-plus" >
 
</i>
Download
</button>
<!-- <iframe id="visualizador"></iframe> -->
  <!-- <embed ng-src="{{content}}" style="width:200px;height:200px;"></embed> -->
  </form>
      </div>
    </div>
  </div>
  <!-- Row end -->
</div>
 
Controller:
 
workforce.config(['$stateProvider', '$urlRouterProvider',function($stateProvider, $urlRouterProvider) {
    $stateProvider
    
    .state('report_dashboard.report_opportunity',{
        url : '/report_opportunity',
        templateUrl : 'app/report/report_opportunity/report_sample.html',
        controller : function($scope,companyservice,$state,Auth,$http,$sce) {
       
        // $scope.user = {companyId:Auth.companyId,webUserId:Auth.webUserId};
        $scope.user = {};
        $scope.loadCompanies = function () {
        $scope.companyId=$scope.user.companyid;
        $scope.webId=$scope.user.webid;
        $scope.content = {};
              $http.post(server_url+'getleadreport',$scope.user,{responseType: 'arraybuffer'}).success(function(response){
        var fileName = "file.pdf";
                    var a = document.createElement("a");
                    document.body.appendChild(a);
                    a.style = "display: none";
        var file = new Blob([(response)], {type: 'application/pdf'});
           var fileURL = URL.createObjectURL(file);
           $scope.content = $sce.trustAsResourceUrl(fileURL);
           a.href = fileURL;
                    a.download = fileName;
                    a.click();
               
                 });
         };
        },
        data : {requireLogin : true,name: 'report'},
    });
    
}]);
 
ReportController.Java
 
@RestController
public class ReportController {
 
@RequestMapping(value = "/getleadreport", method = RequestMethod.POST)
public byte[] PDF(@RequestBody Map<String, Integer> map,
HttpServletResponse httpServletResponse,
HttpServletRequest httpServletRequest) throws JRException,
IOException, ClassNotFoundException {
OutputStream os=null;
ByteArrayOutputStream baos=null;
Connection connection=null;
try
{
InputStream jrxml = ReportController.class
.getResourceAsStream("jasper\ss.jrxml");
 
int cid = (int) map.get("companyid");
int wid = (int) map.get("webid");
   connection = SQLMyUtilConnection.establishConnection();
JasperPrint jasperPrint = simpleReport(cid, wid, jrxml,connection);
baos = new ByteArrayOutputStream();
 
os = httpServletResponse.getOutputStream();
httpServletResponse.setHeader("Content-Disposition",
"inline; filename=file.pdf");
httpServletResponse.setContentType("application/pdf");
httpServletResponse.setStatus(HttpServletResponse.SC_OK);
httpServletResponse
.setHeader("Cache-Control",
"private, must-revalidate, post-check=0, pre-check=0, max-age=1");
httpServletResponse.setHeader("Pragma", "public");
JasperExportManager.exportReportToPdfStream(jasperPrint, baos);
os.write(baos.toByteArray());
}
finally
{
os.close();
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return baos.toByteArray();
 
}
 
public JasperPrint simpleReport(int compId, int webId, InputStream jrxml,Connection connection)
throws ClassNotFoundException, FileNotFoundException {
JasperPrint jasperPrint = null;
try {
InputStream input = ReportController.class
.getResourceAsStream("jasper\sample.json");
JsonDataSource datasource = new JsonDataSource(input);
 
InputStream jrxml1 = ReportController.class
.getResourceAsStream("jasper\ss.jrxml");
JasperDesign jasperDesign = JRXmlLoader
                   .load(jrxml1);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
Map parameters = new HashMap();
           jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, datasource);
           
           
           
           
           parameters.put(JsonQueryExecuterFactory.JSON_INPUT_STREAM, input);
          // JasperFillManager.fillReportToFile(jasperReport, parameters);
           
           
           
           JasperExportManager.exportReportToPdfFile(jasperPrint, "BasicReport.pdf");
           JasperViewer.viewReport(jasperPrint);
} catch (JRException ex) {
ex.printStackTrace();
}
 
 
return jasperPrint;
}
}
 
Jrxml file"
 
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.2.0.final using JasperReports Library version 6.2.0  -->
<!-- 2016-02-26T18:45:45 -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="jsonfile" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" >
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="jsonDatasource"/>
<queryString language="json">
<![CDATA[employees]>
</queryString>
<field name="firstName" class="java.lang.String">
<fieldDescription><![CDATA[firstName]]></fieldDescription>
</field>
<field name="lastName" class="java.lang.String">
<fieldDescription><![CDATA[lastName]]></fieldDescription>
</field>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch"/>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="61" splitType="Stretch">
<staticText>
<reportElement x="169" y="0" width="100" height="30" />
<text><![CDATA[firstName]]></text>
</staticText>
<staticText>
<reportElement x="387" y="0" width="100" height="30" />
<text><![CDATA[lastName]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="125" splitType="Stretch">
<textField>
<reportElement x="169" y="22" width="100" height="30" />
<textFieldExpression><![CDATA[$F{firstName}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="387" y="29" width="100" height="30" 
/>
<textFieldExpression><![CDATA[$F{lastName}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
 
 

 

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...