Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.12 KB | None | 0 0
  1. @RequestMapping(value="/getleadreport", method = RequestMethod.POST)
  2. public byte[] PDF(HttpServletResponse httpServletResponse) throws JRException, IOException, ClassNotFoundException {
  3. simpleReport();
  4. ByteArrayOutputStream baos = new ByteArrayOutputStream();
  5. ServletOutputStream servletOutputStream = httpServletResponse.getOutputStream();
  6. JasperExportManager.exportReportToPdfStream(jasperPrint,baos);
  7.  
  8. System.out.println("Addee");
  9. /* httpServletResponse.setHeader("Content-Disposition", "inline; filename=file.pdf");
  10. httpServletResponse.setContentType("application/pdf");*/
  11. System.out.println(baos.toByteArray());
  12. //System.out.println(new String(baos.toByteArray(), "UTF-8"));
  13.  
  14.  
  15. OutputStream os = httpServletResponse.getOutputStream();
  16. httpServletResponse.setHeader("Content-Disposition", "inline; filename=file.pdf");
  17. httpServletResponse.setContentType("application/pdf");
  18. /* httpServletResponse.setStatus(HttpServletResponse.SC_OK);
  19. httpServletResponse.setHeader("Cache-Control","private, must-revalidate, post-check=0, pre-check=0, max-age=1");
  20. httpServletResponse.setHeader("Pragma","public"); */
  21. os.write(baos.toByteArray());
  22. os.close();
  23.  
  24.  
  25. /*Map<String, byte[]> output =new HashMap<String, byte[]>();
  26.  
  27. //output.put("success",true);
  28. output.put("data",baos.toByteArray());
  29.  
  30. return output;
  31. */
  32. return baos.toByteArray();
  33.  
  34.  
  35. }
  36.  
  37. public void simpleReport() throws ClassNotFoundException {
  38. try {
  39. JasperReport jasperReport= JasperCompileManager.compileReport("D://new_prject//workforceapi//WebContent//jasper//ss.jrxml");
  40. HashMap<String , Integer> jasperParameter = new HashMap<String , Integer>();
  41. jasperParameter.put("company_id", 2);
  42. jasperParameter.put("web_id", 2);
  43. Connection connection = Connectiom.establishConnection();
  44. jasperPrint = JasperFillManager.fillReport(jasperReport,jasperParameter,connection);
  45. String property = System.getProperty( "catalina.home" );
  46. JasperExportManager.exportReportToPdfFile(jasperPrint, property+"\webapps\jasper\report.pdf");
  47.  
  48. } catch (JRException ex) {
  49. ex.printStackTrace();
  50. }
  51. }
  52.  
  53. @RequestMapping(value = "/getleadreport11", method = RequestMethod.POST)
  54. public @ResponseBody
  55. InputStream retrievePDFFile() throws FileNotFoundException
  56. {
  57. String property = System.getProperty( "catalina.home" );
  58. InputStream inputStream = new FileInputStream(property+"\webapps\jasper\report.pdf");
  59. return inputStream;
  60. }
  61.  
  62. workforce.config(['$stateProvider', '$urlRouterProvider',function($stateProvider, $urlRouterProvider) {
  63. $stateProvider
  64.  
  65. .state('report_dashboard.report_opportunity',{
  66. url : '/report_opportunity',
  67. templateUrl : 'app/report/report_opportunity/report_sample.html',
  68. controller : function($scope,companyservice,$state,Auth,$http,$sce) {
  69.  
  70. $scope.user = {companyId:Auth.companyId,webUserId:Auth.webUserId};
  71. // $scope.user = {user:"Manish@trinitymobility.com",pass:"123456"}
  72. $scope.loadCompanies = function () {
  73. $scope.content = {};
  74. console.log('in');
  75. //$http.post(server_url+'getleadreport', {responseType:'arraybuffer'}).success( function(response) {
  76.  
  77.  
  78. $http.post(server_url+'getleadreport',{responseType: 'arraybuffer'}).success(function(response){
  79. console.log(" responce is : "+response);
  80. var file = new Blob([response], {type: 'application/pdf'});
  81. console.log(" file is : "+file);
  82. var fileURL = URL.createObjectURL(file);
  83.  
  84. // document.getElementById('visualizador').setAttribute('src',fileURL);
  85. //$scope.content = fileURL;
  86. console.log(" fileURL is : "+fileURL);
  87. $scope.content = $sce.trustAsResourceUrl(fileURL);
  88. console.log("content is : " + $scope.content);
  89. window.open(fileURL);
  90. // window.open(fileURL,'Download');
  91. });
  92. };
  93. //$scope.loadCompanies();
  94. },
  95. data : {requireLogin : true,name: 'report'},
  96. });
  97.  
  98. }]);
  99.  
  100. <div class="container-fluid" id="table-content-wrapper">
  101. <!-- Row start -->
  102. <div class="row">
  103. <div class="col-xs-12">
  104. <div class="panel panel-default">
  105. <div class="panel-heading clearfix">
  106. <i class="icon-calendar"></i>
  107. <h3 class="panel-title">Lead</h3>
  108. </div>
  109.  
  110.  
  111. <div class="panel-body table-responsive">
  112. <div>
  113. <button type="button" class="btn btn-sm btn-success" ng-click="loadCompanies()">
  114. <i class="glyphicon glyphicon-plus" >
  115.  
  116. </i>
  117. Add
  118. </button>
  119. <!-- <iframe id="visualizador"></iframe> -->
  120. <object ng-src="{{content}}" style="width:200px;height:200px;"></object >
  121. </div>
  122. </div>
  123. </div>
  124. <!-- Row end -->
  125. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement