Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @RequestMapping(value="/getleadreport", method = RequestMethod.POST)
- public byte[] PDF(HttpServletResponse httpServletResponse) throws JRException, IOException, ClassNotFoundException {
- simpleReport();
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ServletOutputStream servletOutputStream = httpServletResponse.getOutputStream();
- JasperExportManager.exportReportToPdfStream(jasperPrint,baos);
- System.out.println("Addee");
- /* httpServletResponse.setHeader("Content-Disposition", "inline; filename=file.pdf");
- httpServletResponse.setContentType("application/pdf");*/
- System.out.println(baos.toByteArray());
- //System.out.println(new String(baos.toByteArray(), "UTF-8"));
- OutputStream 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"); */
- os.write(baos.toByteArray());
- os.close();
- /*Map<String, byte[]> output =new HashMap<String, byte[]>();
- //output.put("success",true);
- output.put("data",baos.toByteArray());
- return output;
- */
- return baos.toByteArray();
- }
- public void simpleReport() throws ClassNotFoundException {
- try {
- JasperReport jasperReport= JasperCompileManager.compileReport("D://new_prject//workforceapi//WebContent//jasper//ss.jrxml");
- HashMap<String , Integer> jasperParameter = new HashMap<String , Integer>();
- jasperParameter.put("company_id", 2);
- jasperParameter.put("web_id", 2);
- Connection connection = Connectiom.establishConnection();
- jasperPrint = JasperFillManager.fillReport(jasperReport,jasperParameter,connection);
- String property = System.getProperty( "catalina.home" );
- JasperExportManager.exportReportToPdfFile(jasperPrint, property+"\webapps\jasper\report.pdf");
- } catch (JRException ex) {
- ex.printStackTrace();
- }
- }
- @RequestMapping(value = "/getleadreport11", method = RequestMethod.POST)
- public @ResponseBody
- InputStream retrievePDFFile() throws FileNotFoundException
- {
- String property = System.getProperty( "catalina.home" );
- InputStream inputStream = new FileInputStream(property+"\webapps\jasper\report.pdf");
- return inputStream;
- }
- 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 = {user:"Manish@trinitymobility.com",pass:"123456"}
- $scope.loadCompanies = function () {
- $scope.content = {};
- console.log('in');
- //$http.post(server_url+'getleadreport', {responseType:'arraybuffer'}).success( function(response) {
- $http.post(server_url+'getleadreport',{responseType: 'arraybuffer'}).success(function(response){
- console.log(" responce is : "+response);
- var file = new Blob([response], {type: 'application/pdf'});
- console.log(" file is : "+file);
- var fileURL = URL.createObjectURL(file);
- // document.getElementById('visualizador').setAttribute('src',fileURL);
- //$scope.content = fileURL;
- console.log(" fileURL is : "+fileURL);
- $scope.content = $sce.trustAsResourceUrl(fileURL);
- console.log("content is : " + $scope.content);
- window.open(fileURL);
- // window.open(fileURL,'Download');
- });
- };
- //$scope.loadCompanies();
- },
- data : {requireLogin : true,name: 'report'},
- });
- }]);
- <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>
- <button type="button" class="btn btn-sm btn-success" ng-click="loadCompanies()">
- <i class="glyphicon glyphicon-plus" >
- </i>
- Add
- </button>
- <!-- <iframe id="visualizador"></iframe> -->
- <object ng-src="{{content}}" style="width:200px;height:200px;"></object >
- </div>
- </div>
- </div>
- <!-- Row end -->
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement