60 lines
1.5 KiB
PHP
60 lines
1.5 KiB
PHP
<?php
|
|
namespace App\Services;
|
|
|
|
use App\Libraries\CouponPDF;
|
|
use App\Models\Coupon;
|
|
|
|
class CreatePDF{
|
|
|
|
protected $view;
|
|
protected $pdf;
|
|
|
|
|
|
public function __construct($view)
|
|
{
|
|
$this->view = $view;
|
|
}
|
|
|
|
public function create($fewo, $contents, $name='test.pdf', $output='stream'){
|
|
|
|
header('Content-type: text/html; charset=UTF-8') ;//chrome
|
|
//dd($data);
|
|
$data = [
|
|
'contents' => $contents,
|
|
'fewo' => $fewo,
|
|
];
|
|
$pdf = app('dompdf.wrapper');
|
|
$pdf->getDomPDF()->set_option("enable_php", true);
|
|
$pdf->loadView($this->view, $data);
|
|
$pdf->setPaper('A4', 'portrait');
|
|
|
|
|
|
if($output === 'stream'){
|
|
return $pdf->stream($name);
|
|
}
|
|
if($output === 'download'){
|
|
return $pdf->download($name);
|
|
}
|
|
|
|
if($output === 'save'){
|
|
/* $dir = $invoice->getInvoiceStorageDir();
|
|
if(!Storage::disk('invoices')->exists( $dir )){
|
|
Storage::disk('invoices')->makeDirectory($dir); //creates directory
|
|
}
|
|
$path = Storage::disk('invoices')->getAdapter()->getPathPrefix();
|
|
|
|
if($preview){
|
|
$filename = "preview.pdf";
|
|
}else{
|
|
$filename = $invoice->invoice_number.".pdf";
|
|
}
|
|
|
|
$pdf->save($path.$dir.$filename);
|
|
|
|
return $path.$dir.$filename; */
|
|
//return $pdf->download($name);
|
|
}
|
|
}
|
|
|
|
}
|
|
?>
|