Кукловод не найден в laravel-pdfPhp

Кемеровские программисты php общаются здесь
Ответить
Anonymous
 Кукловод не найден в laravel-pdf

Сообщение Anonymous »

Я пытаюсь создать PDF-файл на основе HTML-кода в своем проекте Laravel. Я установил spatie/laravel-pdf ^1.5 с помощью композитора. Кажется, проблема связана с кукловодом, но я не уверен, в чем может быть проблема.
Переменная $data в обновленной функции модели PDF отправляется HTML-код в строке, которая модифицируется, а затем преобразуется в PDF с помощью пакета spatie/laravel-pdf, однако при попытке создать PDF-файл возникает ошибка, сообщающая, что Puppeteer не найден. Установка Puppeteer с помощью npm i -g puppeteer не меняет вывод ошибок.
composer.lock
{
"name": "spatie/laravel-pdf",
"version": "1.5.0",
"source": {
"type": "git",
"url": "https://github.com/spatie/laravel-pdf.git",
"reference": "8c880bf8d386b9580fcac6c5b99b2d3a6b1becbf"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/spatie/lar ... 3a6b1becbf",
"reference": "8c880bf8d386b9580fcac6c5b99b2d3a6b1becbf",
"shasum": ""
},
"require": {
"illuminate/contracts": "^10.0|^11.0",
"php": "^8.2",
"spatie/browsershot": "^4.0",
"spatie/laravel-package-tools": "^1.16.1",
"spatie/temporary-directory": "^2.2.1"
},
"require-dev": {
"ext-imagick": "*",
"larastan/larastan": "^2.7.0",
"laravel/pint": "^1.13.7",
"nunomaduro/collision": "^7.10",
"orchestra/testbench": "^8.18",
"pestphp/pest": "^2.30",
"pestphp/pest-plugin-arch": "^2.5",
"pestphp/pest-plugin-laravel": "^2.2",
"phpstan/extension-installer": "^1.3.1",
"phpstan/phpstan-deprecation-rules": "^1.1.4",
"phpstan/phpstan-phpunit": "^1.3.15",
"spatie/image": "^3.3.2",
"spatie/laravel-ray": "^1.33",
"spatie/pdf-to-image": "^2.2",
"spatie/pdf-to-text": "^1.52.1",
"spatie/pest-expectations": "^1.5",
"spatie/pest-plugin-snapshots": "^2.1",
"spatie/pixelmatch-php": "^1.0",
"wnx/sidecar-browsershot": "^2.0"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"Spatie\\LaravelPdf\\PdfServiceProvider"
],
"aliases": {
"LaravelPdf": "Pdf"
}
}
},
"autoload": {
"files": [
"src/Support/functions.php"
],
"psr-4": {
"Spatie\\LaravelPdf\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Freek Van der Herten",
"email": "freek@spatie.be",
"role": "Developer"
}
],
"description": "Create PDFs in Laravel apps",
"homepage": "https://github.com/spatie/laravel-pdf",
"keywords": [
"laravel",
"laravel-pdf",
"spatie"
],
"support": {
"issues": "https://github.com/spatie/laravel-pdf/issues",
"source": "https://github.com/spatie/laravel-pdf/tree/1.5.0"
},
"time": "2024-04-08T11:11:24+00:00"
},

composer.json
"require": {
"php": "^8.2",
"awcodes/filament-tiptap-editor": "^3.3",
"filament/filament": "^3.2",
"laravel/framework": "^11.0",
"laravel/tinker": "^2.9",
"spatie/laravel-pdf": "^1.5"
},

Модель PDF
Импорт
use Spatie\LaravelPdf\Facades\Pdf as PdfGen;
use Spatie\Browsershot\Browsershot;

protected static function boot()
{
parent::boot();

static::updated(function ($data) {
$html = $data->content;
$html = ''.$html.'';
$html = ''. file_get_contents('css/awcodes/tiptap-editor/tiptap.css') .''.$html;
$html = ''.file_get_contents('https://stackpath.bootstrapcdn.com/boot ... ap.min.css').''.$html;
$dom = new \DOMDocument();
$dom->loadHTML($html);
$images = $dom->getElementsByTagName('img');
foreach ($images as $image) {
$src = $image->getAttribute('src');
$image->setAttribute('src', public_path($src));
$type = pathinfo(public_path($src), PATHINFO_EXTENSION);
$data = file_get_contents(public_path($src));
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
$image->setAttribute('src', $base64);
}
$html = $dom->saveHTML();
$html = str_replace('', '', $html);
$html = str_replace('', '', $html);
if (file_exists('output.pdf'))
unlink('output.pdf');
$pdf = PdfGen::html($html)->save('output.pdf');
file_put_contents('output.html', $html);
});
}

Что я сделал
Используя обычный ->save()
$pdf = PdfGen::html($html)->save('output.pdf');

Ошибка:
The command "node "C:\Users\user\homestead\code\filament2\vendor\spatie\browsershot\src/../bin/browser.cjs" "{""url"":""file:\/\/C:\\Users\\user\\AppData\\Local\\Temp\\1426089947-0494949001713261683\\index.html"",""action"":""pdf"",""options"":{""path"":""output.pdf"",""args"":[],""viewport"":{""width"":800,""height"":600},""displayHeaderFooter"":false,""printBackground"":true}}"" failed. Exit Code: 1(General error) Working directory: C:\Users\user\homestead\code\filament2\public Output: ================ Error Output: ================ 'node' is not recognized as an internal or external command, operable program or batch file.

Добавление ->setNodeBinary()
$pdf = PdfGen::html($html)->setNodeBinary("C:\\Program Files\\nodejs\\node.exe")->save('output.pdf'); // Verified that this is using the correct node path.

Ошибка:
Call to undefined method Spatie\LaravelPdf\PdfBuilder::setNodeBinary()

Использование ->withBrowsershot()
$pdf = PdfGen::html($html)->withBrowsershot(function (Browsershot $browsershot) {
$browsershot->setNodeBinary("C:\\Program Files\\nodejs\\node.exe");
})->save('output.pdf');

Ошибка:
The command ""C:\Program Files\nodejs\node.exe" "C:\Users\user\homestead\code\filament2\vendor\spatie\browsershot\src/../bin/browser.cjs" "{""url"":""file:\/\/C:\\Users\\user\\AppData\\Local\\Temp\\831105329-0121756001713262165\\index.html"",""action"":""pdf"",""options"":{""path"":""output.pdf"",""args"":[],""viewport"":{""width"":800,""height"":600},""displayHeaderFooter"":false,""printBackground"":true}}"" failed. Exit Code: 1(General error) Working directory: C:\Users\user\homestead\code\filament2\public Output: ================ Error Output: ================ [Error: ENOENT: no such file or directory, mkdtemp 'undefined\temp\puppeteer_dev_chrome_profile-XXXXXX'] { errno: -4058, code: 'ENOENT', syscall: 'mkdtemp', path: 'undefined\\temp\\puppeteer_dev_chrome_profile-XXXXXX' }

Добавление ->setNpmBinary() и ->newHeadless()
The command ""C:\Program Files\nodejs\node.exe" "C:\Users\ic10\homestead\code\filament2\vendor\spatie\browsershot\src/../bin/browser.cjs" "{""url"":""file:\/\/C:\\Users\\ic10\\AppData\\Local\\Temp\\805633131-0807926001713262416\\index.html"",""action"":""pdf"",""options"":{""path"":""output.pdf"",""args"":[],""viewport"":{""width"":800,""height"":600},""displayHeaderFooter"":false,""newHeadless"":true,""printBackground"":true}}"" failed. Exit Code: 1(General error) Working directory: C:\Users\ic10\homestead\code\filament2\public Output: ================ Error Output: ================ [Error: ENOENT: no such file or directory, mkdtemp 'undefined\temp\puppeteer_dev_chrome_profile-XXXXXX'] { errno: -4058, code: 'ENOENT', syscall: 'mkdtemp', path: 'undefined\\temp\\puppeteer_dev_chrome_profile-XXXXXX' }

Использование ->setIncludePath() внутри функции ->withBrowsershot()
$pdf = PdfGen::html($html)->withBrowsershot(function (Browsershot $browsershot) {
$browsershot->setIncludePath("C:\\Program Files\\nodejs\\node.exe");
})->save('output.pdf');

Ошибка:
The command "node "C:\Users\user\homestead\code\filament2\vendor\spatie\browsershot\src/../bin/browser.cjs" "{""url"":""file:\/\/C:\\Users\\user\\AppData\\Local\\Temp\\2023162371-0794294001713262550\\index.html"",""action"":""pdf"",""options"":{""path"":""output.pdf"",""args"":[],""viewport"":{""width"":800,""height"":600},""displayHeaderFooter"":false,""printBackground"":true}}"" failed. Exit Code: 1(General error) Working directory: C:\Users\user\homestead\code\filament2\public Output: ================ Error Output: ================ 'node' is not recognized as an internal or external command, operable program or batch file.


Подробнее здесь: https://stackoverflow.com/questions/783 ... aravel-pdf
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Php»