Generated picture in mpdf

♀尐吖头ヾ 提交于 2019-12-25 05:33:49

问题


I have generated barcode using zend barcode and out it in a kohana 3.3.1 controller and it looks like this.

<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Barcode extends Controller_Base {

public function after()
{
    $this->response->headers('Content-Type','image/gif');
    parent::after();
}

public function action_Letter()
{
    Helper_Barcode::generate_barcode(Enum_Post::LETTER);
}

}

It works great on view sites but when I'm using it in mpdf view like:

<div><img src="/Barcode/Letter"></div>   

It gives me error:

mPDF error: IMAGE Error (/Barcode/Letter): Error parsing image file - image type not recognised, and not supported by GD imagecreate

Anyone know what may be wrong?


回答1:


I had also problems parsing images to mPDF library vía POST or making an AJAX call. When I send some HTML String with an tag on it, it showed me the following error:

“mPDF error: IMAGE Error (http://www.xxxxxx.com/folder/my_image.jpg): Error parsing image file - image type not recognised, and not supported by GD imagecreate”

My solution was, instead of sending tags in my HTML code, send a custom identifier like:

<body> 
code code code 

insert_image:my_image.jpg 

code code code 
</body>

—> All this html will be sent in a POST field

Then, in the PHP that will use mPDF I replaced that custom code with the correct tags:

<?php
$content_html = $_POST[‘my_html_code_to_pdf']; // THE POSTED FIELD WITH ALL MY HTML CODE

$content_html = preg_replace("/insert_image*:([a-z_0-9.]*)/“, " <img src='http://www.xxxxxx.com/folder/$1'/> ", $content_html);

$mpdf=new mPDF();
$mpdf->WriteHTML($content_html);
$mpdf->Output();
exit;
?>

And it worked!

Hope this helps!



来源:https://stackoverflow.com/questions/20543677/generated-picture-in-mpdf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!