Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use IlluminateHttpRequest;
- use PHPJasperPHPJasper;
- use AppModelUser;
- class ReportController extends Controller
- {
- public function index()
- {
- $output = public_path() . '/reports/' . time() . '_MidiaSocial';
- $input = public_path().'/reports/Sistema.jrxml';
- $report = new PHPJasper;
- $report->process(
- $input,
- $output,
- array("pdf"),
- array(),
- [
- 'driver' => 'generic',
- 'host' => env('DB_HOST', 'localhost'),
- 'port' => env('DB_PORT', '3306'),
- 'database' => env('DB_DATABASE', 'calculosorte'),
- 'username' => env('DB_USERNAME', 'root'),
- 'password' => env('DB_PASSWORD', ''),
- 'jdbc_driver' => 'com.mysql.jdbc.Driver',
- 'jdbc_url' => 'jdbc:mysql://'.env('DB_HOST', 'localhost').':'.env('DB_PORT', '3306').';databaseName='.env('DB_DATABASE', 'calculosorte'),
- 'jdbc_dir' => base_path().env('JDBC_DIR', 'vendor/geekcom/phpjasper/bin/jasperstarter/jdbc/')
- ]
- )->execute();
- $file = $output.'.pdf';
- $path = $file;
- if (!file_exists($file)) {
- abort(404);
- }
- //caso tenha sido gerado pego o conteudo
- $file = file_get_contents($file);
- //deleto o arquivo gerado, pois iremos mandar o conteudo para o navegador
- unlink($path);
- // retornamos o conteudo para o navegador que Γra abrir o PDF
- return response($file, 200)
- ->header('Content-Type', 'application/pdf')
- ->header('Content-Disposition', 'inline; filename="midia_social.pdf"');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement