gpt4 book ai didi

php - Laravel-Snappy 抛出错误 500 没有更多信息

转载 作者:行者123 更新时间:2023-12-04 04:24:31 25 4
gpt4 key购买 nike

我想使用 barryvdh\laravel-snappy 创建 PDF 文件。我遵循了 github 页面上的所有步骤,但每当我使用像

这样的函数时
$pdf->output();
$pdf->download("test.pdf");

我收到服务器错误。

我尝试使用安装程序以及 Composer 依赖项在 Windows 上安装 wkthmltopdf。我清除了缓存,使用了 composer update、dump-autoload 等。

这是我 Controller 中的函数:

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,

当我在 $pdf 上使用 dd 时,在调用输出、下载、内联等函数之前,我得到以下响应:

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"
}

最佳答案

将二进制路径改为

  'pdf' => array(
'enabled' => true,
'binary' => '/usr/local/bin/wkhtmltopdf', //for ubuntu
// 'binary' => '"C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe"', //for windows
'timeout' => false,
'options' => array(),
'env' => array(),
),
'image' => array(
'enabled' => true,
'binary' => '/usr/local/bin/wkhtmltoimage', //for ubuntu
// 'binary' => '"C:\Program Files\wkhtmltopdf\bin\wkhtmltoimage.exe"', //for windows
'timeout' => false,
'options' => array(),
'env' => array(),
),

你已经为 ubuntu 设置好了。

关于php - Laravel-Snappy 抛出错误 500 没有更多信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58096326/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com