spiritix/php-chrome-html2pdf

Binary error

abross86 opened this issue · 1 comments

I am getting a binary error whenever I try to convert(). I installed using composer, running PHP 8.2.5, node 16.16.0 on macOS. I have installed chromium and can see the chromium process

Update: I noticed that the Chromium process is actually crashing immediately. It runs fine outside of the Apache environment on the machine, both headless and not. This is on macOS 13.3.1 (Intel), and I wonder if it may be caused by code-signing/sandbox issues. Has anyone gotten puppeteer to work in a similar environment?

Any help would be appreciated. Thanks!

The error:
PHP Fatal error: Uncaught Spiritix\\Html2Pdf\\ConverterException: Binary error: node:internal/process/promises:279\n triggerUncaughtException(err, true /* fromPromise */);\n ^\n\n[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "#<ErrorEvent>".] {\n code: 'ERR_UNHANDLED_REJECTION'\n}\n in /HTTPServer/htdocs/phppdf/vendor/spiritix/php-chrome-html2pdf/src/Spiritix/Html2Pdf/Converter.php:188\nStack trace:\n#0 /HTTPServer/htdocs/phppdf/index.php(41): Spiritix\\Html2Pdf\\Converter->convert()\n#1 {main}\n thrown in /HTTPServer/htdocs/phppdf/vendor/spiritix/php-chrome-html2pdf/src/Spiritix/Html2Pdf/Converter.php on line 188

Here is a simple example that throws the error:

require __DIR__ . '/vendor/autoload.php';

use Spiritix\Html2Pdf\Converter;
use Spiritix\Html2Pdf\Input\UrlInput;
use Spiritix\Html2Pdf\Output\EmbedOutput;

$input = new UrlInput();
$input->setUrl('https://www.google.com');
$converter = new Converter($input, new EmbedOutput() );
$converter->setNodePath('/usr/local/bin/node');

$converter->setOptions([
	'displayHeaderFooter' => false,
    'printBackground' => true,
    'mediaType' => 'screen',
    'lowquality' => true,
    'dpi' => 75,
    'pageWaitFor' => 1000,
    'landscape' => false,
    'scale' => 0.86,
    'margin' => array( 'left' => '0.5in', 'top' => '0.5in', 'right' => '0.5in', 'bottom' => '0.5in' )
]);

$pdfData = $converter->convert();

ob_start();
$pdfData->embed('out.pdf', false);

Please try again with the latest version