如何使用 wkhtmltopdf 下载 pdf 修复 Laravel 中的 "The exit status code '-1073741819' "?
How to fix "The exit status code '-1073741819' " in Laravel using wkhtmltopdf to download pdf?
我正在尝试创建一个导出按钮,将 HTML 页面转换为 PDF 然后下载。
我正在使用 Windows 10、XAMPP、Laravel 5.8、wkhtmltopdf。
错误截图如下:
Snappy 配置:
'pdf' => [
'enabled' => true,
'binary' => '"F:\wkhtmltopdf\bin\wkhtmltopdf.exe"',
'timeout' => false,
'options' => [],
'env' => [],
],
'image' => [
'enabled' => true,
'binary' => '"F:\wkhtmltopdf\bin\wkhtmltoimage.exe"',
'timeout' => false,
'options' => [],
'env' => [],
],
导出代码 :
$export_data = $this->exportData($checklist, $request);
$pdf_content = view('checklist.pdf.content')->with($export_data);
$pdf = PDF::loadHTML($pdf_content);
$pdf->setPaper('letter');
if ($checklist->weekly_monthly) {
$pdf->setOrientation('landscape');
}
$pdf->setOption('header-spacing', 30);
$pdf->setOption('header-html', view('checklist.pdf.header')->with($export_data));
$pdf->setOption('footer-html', view('report.pdf.footer'));
return $pdf->download($save_path);
检查您的观点 checklist.pdf.content
。根据我使用 wkhtmltopdf 的经验,99% 的时间,视图都是问题所在。
如果您在视图中使用任何图像或外部样式表,请确保正确定义了它们的路径。如果它们不是,您的 HTML 将在您的浏览器中正常工作,但将其用于 wkhtmltopdf 将引发类似这样的错误。
要为您的图像和外部样式表提供路径,请使用以下格式:
<head>
<link href="{{public_path()}}/css/app.css" rel="stylesheet">
</head>
<body>
<img src="{{public_path()}}/images/test.png" />
</body>
当然,确切的路径可能会根据您的文件夹配置而有所不同,但它们必须可以公开访问,并且应该使用远程路径进行访问。
希望对你有帮助
我正在尝试创建一个导出按钮,将 HTML 页面转换为 PDF 然后下载。
我正在使用 Windows 10、XAMPP、Laravel 5.8、wkhtmltopdf。
错误截图如下:
Snappy 配置:
'pdf' => [
'enabled' => true,
'binary' => '"F:\wkhtmltopdf\bin\wkhtmltopdf.exe"',
'timeout' => false,
'options' => [],
'env' => [],
],
'image' => [
'enabled' => true,
'binary' => '"F:\wkhtmltopdf\bin\wkhtmltoimage.exe"',
'timeout' => false,
'options' => [],
'env' => [],
],
导出代码 :
$export_data = $this->exportData($checklist, $request);
$pdf_content = view('checklist.pdf.content')->with($export_data);
$pdf = PDF::loadHTML($pdf_content);
$pdf->setPaper('letter');
if ($checklist->weekly_monthly) {
$pdf->setOrientation('landscape');
}
$pdf->setOption('header-spacing', 30);
$pdf->setOption('header-html', view('checklist.pdf.header')->with($export_data));
$pdf->setOption('footer-html', view('report.pdf.footer'));
return $pdf->download($save_path);
检查您的观点 checklist.pdf.content
。根据我使用 wkhtmltopdf 的经验,99% 的时间,视图都是问题所在。
如果您在视图中使用任何图像或外部样式表,请确保正确定义了它们的路径。如果它们不是,您的 HTML 将在您的浏览器中正常工作,但将其用于 wkhtmltopdf 将引发类似这样的错误。
要为您的图像和外部样式表提供路径,请使用以下格式:
<head>
<link href="{{public_path()}}/css/app.css" rel="stylesheet">
</head>
<body>
<img src="{{public_path()}}/images/test.png" />
</body>
当然,确切的路径可能会根据您的文件夹配置而有所不同,但它们必须可以公开访问,并且应该使用远程路径进行访问。
希望对你有帮助