From 0b90e6e5128076ae3224f975ded0463248cc02e9 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Wed, 24 May 2017 11:00:35 +0300 Subject: [PATCH] Fix PDF on older IE --- .../Controllers/ClientPortalController.php | 3 ++- app/Models/Invoice.php | 14 ++++++++----- resources/views/invoices/pdf.blade.php | 20 ++++++++++++++++++- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/ClientPortalController.php b/app/Http/Controllers/ClientPortalController.php index b91794a199c1..803127c2cfa4 100644 --- a/app/Http/Controllers/ClientPortalController.php +++ b/app/Http/Controllers/ClientPortalController.php @@ -200,7 +200,8 @@ class ClientPortalController extends BaseController } $invoice = $invitation->invoice; - $pdfString = $invoice->getPDFString(); + $decode = ! request()->base64; + $pdfString = $invoice->getPDFString($decode); header('Content-Type: application/pdf'); header('Content-Length: ' . strlen($pdfString)); diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 36afcdeed62c..c98daa80c182 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -1231,7 +1231,7 @@ class Invoice extends EntityModel implements BalanceAffecting /** * @return bool|string */ - public function getPDFString() + public function getPDFString($decode = true) { if (! env('PHANTOMJS_CLOUD_KEY') && ! env('PHANTOMJS_BIN_PATH')) { return false; @@ -1271,11 +1271,15 @@ class Invoice extends EntityModel implements BalanceAffecting return false; } - if ($pdf = Utils::decodePDF($pdfString)) { - return $pdf; + if ($decode) { + if ($pdf = Utils::decodePDF($pdfString)) { + return $pdf; + } else { + Utils::logError("PhantomJS - Unable to decode: {$pdfString}"); + return false; + } } else { - Utils::logError("PhantomJS - Unable to decode: {$pdfString}"); - return false; + return $pdfString; } } diff --git a/resources/views/invoices/pdf.blade.php b/resources/views/invoices/pdf.blade.php index a92cfff44ab3..13d92ad78ba3 100644 --- a/resources/views/invoices/pdf.blade.php +++ b/resources/views/invoices/pdf.blade.php @@ -114,7 +114,25 @@ var needsRefresh = false; function refreshPDF(force) { - return getPDFString(refreshPDFCB, force); + try { + return getPDFString(refreshPDFCB, force); + } catch (exception) { + $.get('http://ninja.dev/download/kamdswrgu9adbmojwlvmsfyzc6a3zd42?base64=true', function(result) { + refreshPDFCB(result); + }) + return false; + } + + /* + @if (true || isset($usePhantomJS) && $usePhantomJS) + $.get('http://ninja.dev/download/kamdswrgu9adbmojwlvmsfyzc6a3zd42?base64=true', function(result) { + refreshPDFCB(result); + }) + return false; + @else + return getPDFString(refreshPDFCB, force); + @endif + */ } function refreshPDFCB(string) {