cosmetic fixes, enhance profile, fix mails, ...
This commit is contained in:
@@ -5,7 +5,7 @@ namespace App\Repositories\Core;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
Trait DateStats
|
||||
trait DateStats
|
||||
{
|
||||
public static function countByMonth($prev = 0)
|
||||
{
|
||||
|
||||
88
app/Repositories/Core/PDF.php
Normal file
88
app/Repositories/Core/PDF.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
use Barryvdh\DomPDF\Facade\Pdf as DomPDF;
|
||||
use GravityMedia\Ghostscript\Ghostscript;
|
||||
use Mpdf\Mpdf;
|
||||
use Barryvdh\Snappy\Facades\SnappyPdf;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
class PDF
|
||||
{
|
||||
public static function view($view, $data, $filename = 'file.pdf')
|
||||
{
|
||||
\Debugbar::disable();
|
||||
$pdf = DomPDF::loadView($view, $data);
|
||||
return $pdf->download($filename);
|
||||
}
|
||||
|
||||
public static function convertHTML($html)
|
||||
{
|
||||
$mpdf = new Mpdf();
|
||||
$mpdf->WriteHTML($html);
|
||||
return $mpdf->Output();
|
||||
}
|
||||
|
||||
public static function convertURL($url)
|
||||
{
|
||||
$pdf = SnappyPdf::loadFile($url);
|
||||
return $pdf->download('invoice.pdf');
|
||||
}
|
||||
|
||||
public static function convertIfNeeded($filename)
|
||||
{
|
||||
if (self::getVersion($filename) > 1.4) {
|
||||
self::downgrade2($filename);
|
||||
}
|
||||
}
|
||||
|
||||
public static function getVersion($filename)
|
||||
{
|
||||
$pdf = fopen($filename, 'r');
|
||||
if ($pdf) {
|
||||
$line_first = fgets($pdf);
|
||||
fclose($pdf);
|
||||
} else {
|
||||
echo 'error opening the file.';
|
||||
}
|
||||
preg_match_all('!\d+!', $line_first, $matches);
|
||||
$version = implode('.', $matches[0]);
|
||||
|
||||
return (float) $version;
|
||||
}
|
||||
|
||||
public static function downgrade($filename)
|
||||
{
|
||||
$new_filename = $filename.'-temp';
|
||||
$ghostscript = new Ghostscript([
|
||||
'quiet' => false,
|
||||
]);
|
||||
|
||||
$device = $ghostscript->createPdfDevice($new_filename);
|
||||
$device->setCompatibilityLevel(1.4);
|
||||
|
||||
// dump($device);
|
||||
$process = $device->createProcess($filename);
|
||||
// dump($process);
|
||||
// echo '$ ' . $process->getCommandLine() . PHP_EOL;
|
||||
// exit;
|
||||
$process->run(function ($type, $buffer) {
|
||||
if ($type === Process::ERR) {
|
||||
throw new \RuntimeException($buffer);
|
||||
}
|
||||
// print $buffer;
|
||||
});
|
||||
|
||||
unlink($filename);
|
||||
rename($new_filename, $filename);
|
||||
}
|
||||
|
||||
public static function downgrade2($filename)
|
||||
{
|
||||
$new_filename = $filename.'-temp';
|
||||
shell_exec('gs -dBATCH -dCompatibilityLevel=1.4 -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile="'.$new_filename.'" "'.$filename.'"');
|
||||
unlink($filename);
|
||||
rename($new_filename, $filename);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user