php – DOM pdf codeigniter:未找到类’DOMPDF’错误

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

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

2.在libraries文件夹中创建名为Dompdf.PHP的文件

在我的控制器中

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

但我会这个错误.

Message: Class ‘DOMPDF’ not found

Filename: libraries/Dompdf.php

Line Number: 16

I am using latest DOMPDF

最佳答案
在我的情况下.我用这个

$dompdf = new Dompdf\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");

转载注明原文:php – DOM pdf codeigniter:未找到类’DOMPDF’错误 - 代码日志