我在 symfony 4.4 上有一个项目,它仅在本地使用 WhtmlToPDF 和 knp snappy bundle 一切正常,pdf 生成仅需 3 秒,但一旦我切换到 FTP,加载就会变得非常长,大约 1 分钟 10 时它不会崩溃因为时间限制已经过期(即使有 setTimeout),而且我的模板没有正确加载。
例如生成的 PDF 文档是发票,但没有显示徽标等......即使使用绝对 url。
我真的不知道这是从哪里来的。
这里是knp_snappy.yml中的配置
knp_snappy:
process_timeout: 120
pdf:
enabled: true
binary: '/usr/bin/wkhtmltopdf'
options: []
image:
enabled: true
binary: '/usr/bin/wkhtmltoimage'
options: []
这是 symfony 控制器中的配置
private $snappy;
public function __construct(Pdf $snappy)
{
$this->snappy = $snappy;
}
private function generatePDF(Facture $facture, bool $sans_date=false, Request $r)
{
$snappy = $this->snappy;
$header = $this->renderView('/Print/header.html.twig', [
'user' => $facture->getUser()
] );
$footer = $this->renderView('/Print/footer.html.twig', [
'user' => $facture->getUser()
] );
$html_detail = $this->renderView('/Print/page_detail.html.twig', [
'facture' => $facture,
]);
$html_echeancier = $this->renderView('/Print/page_echeancier.html.twig', [
'facture' => $facture
]);
$file = $snappy->getOutputFromHtml($html_detail,[
'header-html' => $header,
'footer-html' => $footer,
'title' => $filename
]);
$filesystem = new Filesystem();
$filesystem->dumpFile($this->getParameter('upload_directory')."/".$filename, $file);
}
}
我已经检查过一切都在本地工作 我还检查了路径 usr/bin/wkhtmltopdf 是否正确 我还检查了使用的版本 process_timeout 已添加用于测试