我被困在这里好几个小时了,想弄清楚这东西到底出了什么问题。当我排除/注释掉javascript部分时,它就起作用了,但是当javascript部分没有注释时,它就不能工作了。我面临的另一个问题是使用{{ asset('js/app.js') }}向视图添加外部资产。我尝试了{{ url(...) }},{{ public_path(...) }},因为它在我的研究之后对一些人有效,但是chrome返回一个错误Not allowed to load local resource, --我只需要这个来添加jquery。如果有另一种添加jquery的方法,请告诉我,尝试CDN没有效果。
我从dompdf转换为snappy,因为我听说它适用于javascript,但现在im仍然有效。我真的需要帮助。
版本: Windows 64位:wkhtmltopdf 0.12.6 (with patched qt)
控制器
<?php
namespace App\Http\Controllers;
use Barryvdh\Snappy\Facades\SnappyPdf as PDF;
class AsdController extends Controller
{
public function index()
{
$pdf = PDF::loadView('asd.index');
$pdf->setOption('enable-javascript', true);
$pdf->setOption('javascript-delay', 13500);
$pdf->setOption('enable-smart-shrinking', true);
$pdf->setOption('no-stop-slow-scripts', true);
return $pdf->download('asd.pdf');
}
}视图
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1 id="sss">This is a Heading</h1>
<p>This is a paragraph.</p>
</body>
<script>
document.getElementById('sss').innerHTML = 'HAHA';
</script>
</html>没有外部资产但带有javascript的错误
The exit status code '-1073741819' says something went wrong: stderr: "Loading pages (1/6)
[> ] 0%
[======> ] 10%
[==============================> ] 50%
" stdout: "" command: "C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf"
--lowquality --enable-javascript --javascript-delay "13500" --enable-smart-shrinking
--no-stop-slow-scripts 外部资产和javascript的错误
The exit status code '-1073741819' says something went wrong: stderr: "Loading pages (1/6)
[> ] 0%
[======> ] 10%
[==============================> ] 50%
Warning: Failed to load http://localhost:8000/js/app.js (ignore)
" stdout: "" command: "C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf"
--lowquality --enable-javascript --javascript-delay "13500"
--enable-smart-shrinking --no-stop-slow-scripts 发布于 2020-12-08 04:04:24
我在Windows x64机器上也遇到了同样的问题。
在0.12.6版本中,wkhtmltopdf默认禁用本地文件访问。
对于使用laravel-snappy,的用户,在config\snappy.php中添加'enable-local-file-access‘选项:
'pdf' => [
'enabled' => true,
'binary' => env('WKHTML_PDF_BINARY', '/usr/local/bin/wkhtmltopdf'),
'timeout' => false,
'options' => [
'enable-local-file-access' => true,
'orientation' => 'landscape',
'encoding' => 'UTF-8'
],
'env' => [],
],
'image' => [
'enabled' => true,
'binary' => env('WKHTML_IMG_BINARY', '/usr/local/bin/wkhtmltoimage'),
'timeout' => false,
'options' => [
'enable-local-file-access' => true,
'orientation' => 'landscape',
'encoding' => 'UTF-8'
],
'env' => [],
],https://stackoverflow.com/questions/64754722
复制相似问题