fixes
This commit is contained in:
79
vendor/vsmoraes/laravel-pdf/src/Dompdf.php
vendored
79
vendor/vsmoraes/laravel-pdf/src/Dompdf.php
vendored
@@ -1,10 +1,13 @@
|
||||
<?php
|
||||
namespace Vsmoraes\Pdf;
|
||||
|
||||
use Dompdf\Options;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class Dompdf implements Pdf
|
||||
{
|
||||
CONST DOWNLOAD_FILENAME = 'dompdf_out.pdf';
|
||||
|
||||
/**
|
||||
* DOMPDF instance
|
||||
*
|
||||
@@ -17,26 +20,24 @@ class Dompdf implements Pdf
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $filename = 'dompdf_out.pdf';
|
||||
|
||||
protected $filename;
|
||||
|
||||
/**
|
||||
* Inject the DOMPDF object
|
||||
*
|
||||
* @param \DOMPDF $dompdf
|
||||
* @param \Dompdf\Dompdf $dompdf
|
||||
*/
|
||||
public function __construct(\DOMPDF $dompdf)
|
||||
public function __construct(\Dompdf\Dompdf $dompdf)
|
||||
{
|
||||
$this->dompdfInstance = $dompdf;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function load($html, $size = 'A4', $orientation = 'portrait')
|
||||
public function load($html, $size = Pdf::DEFAULT_SIZE, $orientation = Pdf::DEFAULT_ORIENTATION)
|
||||
{
|
||||
$this->dompdfInstance->load_html($html);
|
||||
$this->dompdfInstance->loadHtml($html);
|
||||
$this->setPaper($size, $orientation);
|
||||
|
||||
return $this;
|
||||
@@ -45,16 +46,11 @@ class Dompdf implements Pdf
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function filename($filename = null)
|
||||
public function filename($filename)
|
||||
{
|
||||
if ($filename) {
|
||||
$this->filename = $filename;
|
||||
$this->filename = $filename;
|
||||
|
||||
// chain when the filename is set
|
||||
return $this;
|
||||
}
|
||||
|
||||
return $this->filename;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,7 +58,9 @@ class Dompdf implements Pdf
|
||||
*/
|
||||
public function setPaper($size, $orientation)
|
||||
{
|
||||
return $this->dompdfInstance->set_paper($size, $orientation);
|
||||
$this->dompdfInstance->setPaper($size, $orientation);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,36 +68,52 @@ class Dompdf implements Pdf
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
return $this->dompdfInstance->render();
|
||||
$this->dompdfInstance->render();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function clear()
|
||||
public function setOptions(Options $options)
|
||||
{
|
||||
\Image_Cache::clear();
|
||||
$this->dompdfInstance->setOptions($options);
|
||||
|
||||
return true;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function show($options = ['compress' => 1, 'Attachment' => 0])
|
||||
public function getOptions()
|
||||
{
|
||||
return $this->dompdfInstance->getOptions();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function show($acceptRanges = false, $compress = true, $attachment = true)
|
||||
{
|
||||
$options = [
|
||||
'Accept-Ranges' => (int) $acceptRanges,
|
||||
'compress' => (int) $compress,
|
||||
'Attachment' => (int) $attachment,
|
||||
];
|
||||
|
||||
$this->render();
|
||||
$this->clear();
|
||||
$filename = !is_null($this->filename) ? $this->filename : static::DOWNLOAD_FILENAME;
|
||||
|
||||
return $this->dompdfInstance->stream($this->filename(), $options);
|
||||
$this->dompdfInstance->stream($filename, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function download($options = ['compress' => 1, 'Attachment' => 1])
|
||||
public function download()
|
||||
{
|
||||
return new Response($this->show($options), 200, [
|
||||
return new Response($this->show(false, true, true), 200, [
|
||||
'Content-Type' => 'application/pdf',
|
||||
]);
|
||||
}
|
||||
@@ -107,10 +121,19 @@ class Dompdf implements Pdf
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function output($options = ['compress' => 1])
|
||||
public function output($compress = true)
|
||||
{
|
||||
$this->render();
|
||||
$options = [
|
||||
'compress' => (int) $compress,
|
||||
];
|
||||
|
||||
return $this->dompdfInstance->output($options);
|
||||
$this->render();
|
||||
$output = $this->dompdfInstance->output($options);
|
||||
|
||||
if (!is_null($this->filename)) {
|
||||
file_put_contents($this->filename, $output);
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
71
vendor/vsmoraes/laravel-pdf/src/Pdf.php
vendored
71
vendor/vsmoraes/laravel-pdf/src/Pdf.php
vendored
@@ -1,71 +1,92 @@
|
||||
<?php
|
||||
namespace Vsmoraes\Pdf;
|
||||
|
||||
use Dompdf\Options;
|
||||
|
||||
interface Pdf
|
||||
{
|
||||
const DEFAULT_SIZE = 'A4';
|
||||
const DEFAULT_ORIENTATION = 'portrait';
|
||||
|
||||
/**
|
||||
* Loads the HTML to the DOMPDF class
|
||||
*
|
||||
* @param $html
|
||||
* @param string $size
|
||||
* @param string $orientation
|
||||
* @return mixed
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function load($html, $size = 'A4', $orientation = 'portrait');
|
||||
public function load($html, $size = self::DEFAULT_SIZE, $orientation = self::DEFAULT_ORIENTATION);
|
||||
|
||||
/**
|
||||
* Set the filename (full path) to where the file should be saved
|
||||
*
|
||||
* @param null $filename
|
||||
* @return mixed
|
||||
* @param string $filename
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function filename($filename = null);
|
||||
public function filename($filename);
|
||||
|
||||
/**
|
||||
* Set paper size
|
||||
*
|
||||
* @param $size
|
||||
* @param $orientation
|
||||
* @return mixed
|
||||
* @param string $size
|
||||
* @param string $orientation
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setPaper($size, $orientation);
|
||||
|
||||
/**
|
||||
* Render the pdf
|
||||
* Renders the HTML to PDF
|
||||
*
|
||||
* @return mixed
|
||||
* @return $this
|
||||
*/
|
||||
public function render();
|
||||
|
||||
/**
|
||||
* Clear the pdf
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function clear();
|
||||
|
||||
/**
|
||||
* Render the pdf on the browser
|
||||
*
|
||||
* @param array $options
|
||||
* @return mixed
|
||||
* @param bool $acceptRanges
|
||||
* @param bool $compress
|
||||
* @param bool $attachment
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function show($options = ['compress' => 1, 'Attachment' => 0]);
|
||||
public function show($acceptRanges = false, $compress = true, $attachment = true);
|
||||
|
||||
/**
|
||||
* Forces the pdf to download
|
||||
*
|
||||
* @param array $options
|
||||
* @return mixed
|
||||
*/
|
||||
public function download($options = ['compress' => 1, 'Attachment' => 0]);
|
||||
public function download();
|
||||
|
||||
/**
|
||||
* Output the pdf the to file speficied on $this->filename()
|
||||
*
|
||||
* @param array $options
|
||||
* @return mixed
|
||||
* @param bool $compress
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function output($options = ['compress' => 1]);
|
||||
public function output($compress = true);
|
||||
|
||||
/**
|
||||
* Define Dompdf Options
|
||||
* @see https://github.com/dompdf/dompdf/blob/master/src/Options.php
|
||||
*
|
||||
* @param Options $options
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setOptions(Options $options);
|
||||
|
||||
/**
|
||||
* Return the current Dompdf options
|
||||
* @see https://github.com/dompdf/dompdf/blob/master/src/Options.php
|
||||
*
|
||||
* @return Options
|
||||
*/
|
||||
public function getOptions();
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace Vsmoraes\Pdf;
|
||||
|
||||
use Dompdf\Dompdf;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Vsmoraes\Pdf\Dompdf as MyDompdf;
|
||||
|
||||
@@ -11,6 +12,7 @@ class PdfServiceProvider extends ServiceProvider
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $defer = true;
|
||||
|
||||
/**
|
||||
* Register the classes on the IoC container
|
||||
@@ -19,16 +21,12 @@ class PdfServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->bind('DOMPDF', function() {
|
||||
return new \DOMPDF();
|
||||
$this->app->bind(Dompdf::class, function() {
|
||||
return new Dompdf();
|
||||
});
|
||||
|
||||
$this->app->bind('Vsmoraes\Pdf\Pdf', function() {
|
||||
define('DOMPDF_ENABLE_AUTOLOAD', false);
|
||||
|
||||
require_once base_path() . '/vendor/dompdf/dompdf/dompdf_config.inc.php';
|
||||
|
||||
return new Dompdf(new \DOMPDF());
|
||||
$this->app->bind(Pdf::class, function() {
|
||||
return new MyDompdf(new Dompdf());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -39,6 +37,8 @@ class PdfServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function provides()
|
||||
{
|
||||
return ['Vsmoraes\Pdf\Pdf'];
|
||||
return [
|
||||
Pdf::class,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user