Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. use IlluminateHttpRequest;
  2. use PHPJasperPHPJasper;
  3. use AppModelUser;
  4. class ReportController extends Controller
  5. {
  6.  
  7. public function index()
  8. {
  9.  
  10.  
  11. $output = public_path() . '/reports/' . time() . '_MidiaSocial';
  12. $input = public_path().'/reports/Sistema.jrxml';
  13. $report = new PHPJasper;
  14. $report->process(
  15. $input,
  16. $output,
  17. array("pdf"),
  18. array(),
  19. [
  20. 'driver' => 'generic',
  21. 'host' => env('DB_HOST', 'localhost'),
  22. 'port' => env('DB_PORT', '3306'),
  23. 'database' => env('DB_DATABASE', 'calculosorte'),
  24. 'username' => env('DB_USERNAME', 'root'),
  25. 'password' => env('DB_PASSWORD', ''),
  26. 'jdbc_driver' => 'com.mysql.jdbc.Driver',
  27. 'jdbc_url' => 'jdbc:mysql://'.env('DB_HOST', 'localhost').':'.env('DB_PORT', '3306').';databaseName='.env('DB_DATABASE', 'calculosorte'),
  28. 'jdbc_dir' => base_path().env('JDBC_DIR', 'vendor/geekcom/phpjasper/bin/jasperstarter/jdbc/')
  29.  
  30. ]
  31. )->execute();
  32. $file = $output.'.pdf';
  33. $path = $file;
  34.  
  35. if (!file_exists($file)) {
  36. abort(404);
  37. }
  38. //caso tenha sido gerado pego o conteudo
  39. $file = file_get_contents($file);
  40. //deleto o arquivo gerado, pois iremos mandar o conteudo para o navegador
  41. unlink($path);
  42. // retornamos o conteudo para o navegador que Γ­ra abrir o PDF
  43. return response($file, 200)
  44. ->header('Content-Type', 'application/pdf')
  45. ->header('Content-Disposition', 'inline; filename="midia_social.pdf"');
  46.  
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement