【发布时间】:2020-03-18 18:20:41
【问题描述】:
我在 symfony 4 上使用 dompdf 来生成 pdf。 一切都在本地开发中工作。我试图在 Heroku 上的 prod 中启动我的应用程序,但是当我继续生成 PDF 的链接时,我得到了这个:
我告诉自己,这来自需求,他必须错过 Heroku 上的一些东西。
以下是运行 dompdf 所需的列表:
要求
- PHP 5.4.0 或更高版本
- DOM 扩展
- GD 扩展
- MBString 扩展名
- php-font-lib
- php-svg-lib
我有 PHP 7.3
在我的 composer.json 中我有:
"require": {
//...
"ext-mbstring": "*",
"ext-gd": "*",
"dompdf/dompdf": "^0.8.3",
"phenx/php-font-lib": "^0.5.1",
"phenx/php-svg-lib": "^0.3.3",
}
根据 Heroku 文档,DOM 默认启用:
要生成一些 pdf,在我的 php 文件中:
public function generatePdf(OrdreMission $ordre)
{
// Configure Dompdf according to your needs
$pdfOptions = new Options();
$pdfOptions->setIsRemoteEnabled(true);
// Instantiate Dompdf with our options
$dompdf = new Dompdf();
$dompdf->setOptions($pdfOptions);
// $dompdf->set_option('isHtml5ParserEnabled', true);
// Retrieve the HTML generated in our twig file
$html = "<link type='text/css href='/css/bootstrap.min.css' rel='stylesheet'>" . $this->templating->render('ordre_mission/pdf.html.twig', [
'ordre' => $ordre,
]);
// Load HTML to Dompdf
$dompdf->loadHtml($html);
// (Optional) Setup the paper size and orientation 'portrait' or 'portrait'
$dompdf->setPaper('A4', 'portrait');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser (inline view)
$dompdf->stream("mypdf.pdf", [
"Attachment" => false,
]);
}
dev 环境下可以,prod 环境下不行
有人可以帮帮我吗?
【问题讨论】:
标签: php symfony heroku dompdf production