2013-12-12 62 views
0

我生成了barcode使用zend barcode并在kohana 3.3.1 controller它看起来像这样。在mpdf生成的图片

<?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); 
} 

}

它可以在视图站点很大,但是当我使用它在mpdf view像:

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

它给我的错误:

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

任何人都知道什么可能是错的?

回答

2

我也有问题解析图像到mPDF库víaPOST或进行AJAX调用。当我发送一个带有标签的HTML字符串时,它向我显示以下错误:

“mPDF error:IMAGE Error(http://www.xxxxxx.com/folder/my_image.jpg):解析图像文件时出错 - 图像类型未被识别,GD不支持imagecreate”

我的解决办法,而不是在我的HTML代码发送代码,发送类似定制标识符:

<body> 
code code code 

insert_image:my_image.jpg 

code code code 
</body> 

- >所有这个网站将在后场被发送

然后,在PHP将使用mPDF替换th在自定义代码与正确的标签:

<?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; 
?> 

它的工作!

希望这会有所帮助!