【发布时间】:2019-03-10 07:19:54
【问题描述】:
我正在使用 mpdf 生成 pdf。一切都好,直到我切换到 https。之后,仍然可以正确生成 pdf,但图像已损坏。他们的源代码是用 php 模板上的 https 协议正确编写的。而且我还尝试仅使用相对路径。什么都没有。
以下是我班级的示例代码:
public function save_pdf($translate = false){
$this->mpdf = new \Mpdf\Mpdf();
$this->mpdf->CSSselectMedia='mpdf';
//$this->mpdf->showImageErrors = true; // this will log errors into the php log file
$ch = curl_init($this->pdf_css_path . '/configurator-pdf.css');
// this disables ssl check: unsafe
if($this->disable_ssl_check) curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$css = curl_exec($ch);
curl_close($ch);
$template = ($translate) ? $this->pdf_template_url : $this->pdf_template_url_it;
$filename = ($translate) ? $this->pdf_name : $this->pdf_it_name;
$_POST['cid'] = $this->cid;
$json = json_encode($_POST);
$ch = curl_init($template);
// this disables ssl check: unsafe
if($this->disable_ssl_check) curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json', 'Content-Length: ' . strlen($json) ]);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
$html = curl_exec($ch);
curl_close($ch);
$this->mpdf->WriteHTML($css, 1);
$this->mpdf->WriteHTML($html, 2);
$pdf = $this->pdf_destination_path . DS . $filename;
$this->mpdf->Output($pdf, \Mpdf\Output\Destination::FILE);
}
【问题讨论】:
-
您能否检查日志以查看是否正在从服务器请求图像?
-
添加一些调试:
$this->mpdf->showImageErrors = true; -
嗨,我做到了。我得到的是
PHP Fatal error: Uncaught Mpdf\MpdfImageException: Could not find image file (https://www.[mydomain].com/wp-content/themes/[mytheme]/images/[myimage].jpg),但事实上,这个 url 存在并且它是可见的:如果我将它复制粘贴到浏览器中,我会看到图像。所以我真的无法理解……