[英]Using dompdf library in codeigniter
can anybody help me, i'm trying to use dompdf library with codeigniter. 有人可以帮助我吗,我正在尝试将dompdf库与codeigniter一起使用。 When i do it on localhost its work. 当我在本地主机上工作时。 But it's not work properly when my website has been uploaded. 但是上传我的网站后,它无法正常工作。 Here's the library code 这是库代码
<?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-0.6.2/dompdf_config.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);
}
}
this code to call create the pdf, i try to call the view only and it's work but when its called the "pdf" function, the screen is blank. 调用此代码创建pdf,我尝试仅调用视图,并且可以正常工作,但是当其调用“ pdf”功能时,屏幕为空白。
$this->load->library('pdf');
$this->pdf->load_view('mydocument', $data);
$this->pdf->render();
$this->pdf->stream("mydocument.pdf");
and this is structure of my files 这是我文件的结构
As noted in the comments @jagad89 is right about including the autoload file from DOMPDF. 如评论中所述,@ jagad89关于包含来自DOMPDF的自动加载文件是正确的。
Instead of using it with a library wrapper, try installing with Composer 与其与库包装一起使用,不如尝试与Composer一起安装
composer require dompdf/dompdf
And then setup the $config['composer_autoload'] = '/path/to/vendor/autoload.php';
然后设置$config['composer_autoload'] = '/path/to/vendor/autoload.php';
in the config.php
of your application and you should be good to use DOMPDF like this: 在应用程序的config.php
,应该很好地使用DOMPDF,如下所示:
$dompdf = new Dompdf\Dompdf();
$dompdf->loadHtml('hello world');
// Render the HTML as PDF
$dompdf->render();
$dompdf->stream();
Use the following code in controller instead, It shoud be work for you. 在控制器中使用以下代码,应该为您工作。
$this->load->library('pdf');
$this->pdf->load_view('mydocument', $data);
$this->pdf->setPaper('A4', 'portrait');
$this->pdf->render();
$this->pdf->stream("mydocument", array("Attachment" => 0));
Download an archive of dompdf and extract it into the directory where dompdf will reside 下载dompdf档案,并将其解压缩到dompdf将驻留的目录中
Libraries/Pdf Class: 库/ Pdf类:
require_once APPPATH.'libraries/dompdf/autoload.inc.php';
use Dompdf\Dompdf;
class Pdf {
$dompdf = new Dompdf();
$dompdf->loadHtml('<h1>Hello Word</h1>');
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$dompdf->stream('mydocument.pdf');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.