mPDF not rendering images (mPDF error: IMAGE Error Could not find image file)

后端 未结 6 1350
执笔经年
执笔经年 2020-12-17 22:39

We are getting plagued with this which started in April on working server. Everything was fine with our application until the customer reported that PDFs were no longer dis

6条回答
  •  -上瘾入骨i
    2020-12-17 23:35

    With same issue, I found that get_headers() returns:

    "HTTP/1.1 412 Precondition Failed"
    

    Provider says this was due to web firewall, because the request was badly formed and the user_agent not set.

    An ini_set('user_agent', 'Mozilla/5.0'); solved the problem.

    In a WordPress plugin using mpdf, mpdf doesn't use WordPress http classes and doesn't set user_agent. I solved this by adding in mu-plugins:

    global $wp_version;
    
    ini_set('user_agent',apply_filters( 'http_headers_useragent', 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) ));
    

提交回复
热议问题