首页 文章

生成的图片在mpdf中

提问于
浏览
0

我使用 zend barcode 生成 barcode 并在 kohana 3.3.1 controller 中将其输出,它看起来像这样 .

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

谁知道可能有什么问题?

1 回答

  • 2

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

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

    我的解决方案是,不是在我的HTML代码中发送标签,而是发送自定义标识符,如:

    <body> 
    code code code 
    
    insert_image:my_image.jpg 
    
    code code code 
    </body>
    
    • 所有这些html都将在POST字段中发送

    然后,在将使用mPDF的PHP中,我用正确的标记替换了该自定义代码:

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

    它奏效了!

    希望这可以帮助!

相关问题