本文介绍了DOM pdf codeigniter:找不到类"DOMPDF"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将DOM PDF库添加到我的codeigniter应用程序中

I trying to add DOM PDF library to my codeigniter application

1.下载dompdf并将dompdf文件夹复制到库文件夹.

1.Download dompdf and copy the dompdf folder to libraries folder.

2.在库文件夹中创建名为Dompdf.php的文件

2.Create file named Dompdf.php in libraries folder

在我的控制器中

public function pdf_test()
   {
       $this->load->library('Dompdf');
       $this->Dompdf->loadHtml('hello world');
       $this->pdf->render();
       $this->pdf->stream("welcome.pdf");
   }

Dompdf.php

<?php defined('BASEPATH') OR exit('No direct script access allowed');
/**
 * CodeIgniter PDF Library
 *
 * Generate PDF's in your CodeIgniter applications.
 *
 * @package         CodeIgniter
 * @subpackage      Libraries
 * @category        Libraries
 * @author          Chris Harvey
 * @license         MIT License
 * @link            https://github.com/chrisnharvey/CodeIgniter-PDF-Generator-Library
 */
require_once(dirname(__FILE__) . '/dompdf/autoload.inc.php');
class Pdf extends DOMPDF
{
    /**
     * Get an instance of CodeIgniter
     *
     * @access  protected
     * @return  void
     */
    protected function ci()
    {
        return get_instance();
    }
    /**
     * Load a CodeIgniter view into domPDF
     *
     * @access  public
     * @param   string  $view The view to load
     * @param   array   $data The view data
     * @return  void
     */
    public function load_view($view, $data = array())
    {
        $html = $this->ci()->load->view($view, $data, TRUE);
        $this->load_html($html);
    }
}

但是我会出现这个错误.

But i will this error.

文件名:libraries/Dompdf.php

Filename: libraries/Dompdf.php

行号:16

我正在使用最新的DOMPDF

推荐答案

.我用这个

require_once(_MAP."libraries/dompdf/autoload.inc.php");
$dompdf = new Dompdf\DOMPDF();
$html = 'rats :)';
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("sample.pdf");

这篇关于DOM pdf codeigniter:找不到类"DOMPDF"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 14:00