Fix PhantomJS support for multi-page tables and PDF page sizes

This commit is contained in:
Joshua Dwire 2021-10-05 19:34:53 -04:00
parent d68040897f
commit 91d90c87b3

View File

@ -82,11 +82,20 @@ class Phantom
$url = config('ninja.app_url').'/phantom/'.$entity.'/'.$invitation->key.'?phantomjs_secret='.config('ninja.phantomjs_secret'); $url = config('ninja.app_url').'/phantom/'.$entity.'/'.$invitation->key.'?phantomjs_secret='.config('ninja.phantomjs_secret');
info($url); info($url);
$key = config('ninja.phantomjs_key'); $key = config( 'ninja.phantomjs_key' );
$secret = config('ninja.phantomjs_key'); $phantom_url = "https://phantomjscloud.com/api/browser/v2/{$key}/";
$pdf = CurlUtils::post( $phantom_url, json_encode( [
$phantom_url = "https://phantomjscloud.com/api/browser/v2/{$key}/?request=%7Burl:%22{$url}%22,renderType:%22pdf%22%7D"; 'url' => $url,
$pdf = CurlUtils::get($phantom_url); 'renderType' => 'pdf',
'outputAsJson' => false,
'renderSettings' => [
'emulateMedia' => 'print',
'pdfOptions' => [
'preferCSSPageSize' => true,
'printBackground' => true,
],
],
] ) );
$this->checkMime($pdf, $invitation, $entity); $this->checkMime($pdf, $invitation, $entity);
@ -100,14 +109,20 @@ class Phantom
public function convertHtmlToPdf($html) public function convertHtmlToPdf($html)
{ {
$hash = Str::random(32); $key = config( 'ninja.phantomjs_key' );
Cache::put($hash, $html, 300); $phantom_url = "https://phantomjscloud.com/api/browser/v2/{$key}/";
$pdf = CurlUtils::post( $phantom_url, json_encode( [
$url = route('tmp_pdf', ['hash' => $hash]); 'content' => $html,
info($url); 'renderType' => 'pdf',
$key = config('ninja.phantomjs_key'); 'outputAsJson' => false,
$phantom_url = "https://phantomjscloud.com/api/browser/v2/{$key}/?request=%7Burl:%22{$url}%22,renderType:%22pdf%22%7D"; 'renderSettings' => [
$pdf = CurlUtils::get($phantom_url); 'emulateMedia' => 'print',
'pdfOptions' => [
'preferCSSPageSize' => true,
'printBackground' => true,
],
],
] ) );
$response = Response::make($pdf, 200); $response = Response::make($pdf, 200);
$response->header('Content-Type', 'application/pdf'); $response->header('Content-Type', 'application/pdf');