我用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);
}