Question

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?

Was it helpful?

Solution

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!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top