Я хочу создавать PDF-файлы, используя barryvdh \ laravel-snappy.Я выполнил все шаги на странице github, но всякий раз, когда я использую такие функции, как
$pdf->output();
$pdf->download("test.pdf");
, я получаю сообщение об ошибке сервера.
Я пытался установить wkthmltopdf на окна с помощью установщика, а такжезависимость композитора.Я очистил кеш, использовал обновление композитора, дамп-автозагрузку и т. Д.
Это функция в моем контроллере:
public function createInvoice($id)
{
$data = ["data" => "data"];
$pdf = PDF::loadView("invoice.default", $data);
dd($pdf);
return response()->json([
"pdf" => base64_encode($pdf->output())
]);
}
Моя конфигурация snappy.php:
'pdf' => [
'enabled' => true,
'binary' => base_path('vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64'),
'timeout' => false,
'options' => [],
'env' => [],
],
'image' => [
'enabled' => true,
'binary' => base_path('vendor/h4cc/wkhtmltoimage-amd64/bin/wkhtmltoimage-amd64'),
'timeout' => false,
'options' => [],
'env' => [],
],
Моя конфигурация app.php:
'providers' => [
.
.
Barryvdh\Snappy\ServiceProvider::class,
.
.
.
'aliases'=> [
.
.
'PDF' => Barryvdh\Snappy\Facades\SnappyPdf::class,
'SnappyImage' => Barryvdh\Snappy\Facades\SnappyImage::class,
Когда я использую dd на $ pdf, перед вызовом функции, такой как output, download, inline, я получаю следующий ответ:
PdfWrapper {#347
#snappy: IlluminateSnappyPdf {#346
#optionsWithContentCheck: array:4 [
"header-html" => "html"
"footer-html" => "html"
"cover" => "html"
"xsl-style-sheet" => "xsl"
]
-binary: "C:\xampp\htdocs\invoicing\vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64"
-options: array:125 [
"ignore-load-errors" => null
"lowquality" => true
"collate" => null
"no-collate" => null
"cookie-jar" => null
"copies" => null
"dpi" => null
"extended-help" => null
"grayscale" => null
"help" => null
"htmldoc" => null
"image-dpi" => null
"image-quality" => null
"manpage" => null
"margin-bottom" => null
"margin-left" => null
"margin-right" => null
"margin-top" => null
"orientation" => null
"output-format" => null
"page-height" => null
"page-size" => null
"page-width" => null
"no-pdf-compression" => null
"quiet" => null
"read-args-from-stdin" => null
"title" => null
"use-xserver" => null
"version" => null
"dump-default-toc-xsl" => null
"dump-outline" => null
"outline" => null
"no-outline" => null
"outline-depth" => null
"allow" => null
"background" => null
"no-background" => null
"checkbox-checked-svg" => null
"checkbox-svg" => null
"cookie" => null
"custom-header" => null
"custom-header-propagation" => null
"no-custom-header-propagation" => null
"debug-javascript" => null
"no-debug-javascript" => null
"default-header" => null
"encoding" => null
"disable-external-links" => null
"enable-external-links" => null
"disable-forms" => null
"enable-forms" => null
"images" => null
"no-images" => null
"disable-internal-links" => null
"enable-internal-links" => null
"disable-javascript" => null
"enable-javascript" => null
"javascript-delay" => null
"load-error-handling" => null
"load-media-error-handling" => null
"disable-local-file-access" => null
"enable-local-file-access" => null
"minimum-font-size" => null
"exclude-from-outline" => null
"include-in-outline" => null
"page-offset" => null
"password" => null
"disable-plugins" => null
"enable-plugins" => null
"post" => null
"post-file" => null
"print-media-type" => null
"no-print-media-type" => null
"bypass-proxy-for" => null
"proxy" => null
"radiobutton-checked-svg" => null
"radiobutton-svg" => null
"run-script" => null
"disable-smart-shrinking" => null
"enable-smart-shrinking" => null
"stop-slow-scripts" => null
"no-stop-slow-scripts" => null
"disable-toc-back-links" => null
"enable-toc-back-links" => null
"user-style-sheet" => null
"username" => null
"window-status" => null
"zoom" => null
"footer-center" => null
"footer-font-name" => null
"footer-font-size" => null
"footer-html" => null
"footer-left" => null
"footer-line" => null
"no-footer-line" => null
"footer-right" => null
"footer-spacing" => null
"header-center" => null
"header-font-name" => null
"header-font-size" => null
"header-html" => null
"header-left" => null
"header-line" => null
"no-header-line" => null
"header-right" => null
"header-spacing" => null
"replace" => null
"disable-dotted-lines" => null
"cover" => null
"toc" => null
"toc-depth" => null
"toc-font-name" => null
"toc-l1-font-size" => null
"toc-header-text" => null
"toc-header-font-name" => null
"toc-header-font-size" => null
"toc-level-indentation" => null
"disable-toc-links" => null
"toc-text-size-shrink" => null
"xsl-style-sheet" => null
"viewport-size" => null
"redirect-delay" => null
"cache-dir" => null
"keep-relative-links" => null
"resolve-relative-links" => null
]
-env: null
-timeout: false
-defaultExtension: "pdf"
#temporaryFolder: null
+temporaryFiles: []
-logger: NullLogger {#345}
+"fs": Filesystem {#109}
}
#options: []
+"html": """
<!DOCTYPE html>
<html>
<head>
\t<title>Invoice<title>
</head>
<body>
<div class="container">
\t<table class="table table-bordered">
\t\t<thead>
\t\t\t<th>Name</th>
\t\t\t<th>Email</th>
\t\t</thead>
\t\t<tbody>
\t\t\t<tr>
\t\t\t\t<td>TEST</td>
\t\t\t\t<td>BEST</td>
\t\t\t</tr>
\t\t</tbody>
\t</table>
</div>
</body>
</html>
"""
+"file": null
}
Когда я вызываю одну из этих функций, тогда:
{
"message": "Server Error"
}