2013-12-12 61 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; 
?> 

它的工作!

希望這會有所幫助!