You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

mPDF无法渲染加粗文本的问题求助

mPDF无法渲染加粗文本的问题求助

大家好,之前我的mPDF一直工作正常,但最近更新mPDF之后,设置了font-weight:bold的文本突然不生效了。我确认CSS是正常加载的——因为外部CSS里的其他样式都能正常显示,唯独加粗效果没反应,有没有大佬知道可能是什么原因?

下面是我加载mPDF的完整代码:

protected function save_pdf($translate = false){
    $this->mpdf = new \Mpdf\Mpdf();
    if($this->disable_ssl_check)
        $this->mpdf->curlAllowUnsafeSslRequests = true;
    $this->mpdf->CSSselectMedia='mpdf';
    $this->mpdf->showImageErrors = true;

    $ch = curl_init($this->pdf_css_path . '/configurator-pdf.css');
    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);

    $filename = ($translate) ? $this->pdf_name : $this->pdf_it_name;
    $_POST['cid'] = $this->cid;
    $_POST['translate'] = ($translate) ? 1 : 0;
    $json = json_encode($_POST);

    $ch = curl_init($this->pdf_template_url);
    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);
}

补充说明:我是通过curl分别获取外部CSS文件和HTML模板的内容,再用WriteHTML分别加载CSS(参数1指定为样式内容)和HTML(参数2指定为HTML内容),其他样式都能正常渲染,只有加粗效果完全没反应。

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.07 12:17:59