DomPDF.php第34行中的PHPExcel_Writer_Exception:无法加载PDF呈现库

时间:2017-01-25 08:25:08

标签: laravel pdf dompdf snappy

导出为pdf时出错。我尝试过作曲家更新并将内容添加到app.php anf composer.json

 public function exportPDF($request, $orgid)
    {
        /*$pdf = App::make('snappy.pdf.wrapper');
        $pdf->loadHTML('<h1>Test</h1>');
        return $pdf->inline();*/
       $data = User::get()->toArray();
       return Excel::create('itsolutionstuff_example', function($excel) use ($data) {
        $excel->sheet('mySheet', function($sheet) use ($data)
        {
            $sheet->fromArray($data);
        });
       })->download("pdf");
    }

2 个答案:

答案 0 :(得分:1)

您是否设置了pdf渲染器?根据文档,您有3个选择,tcpdf,mPdf和DomPDF。 您必须至少安装其中一个。

composer require mpdf/mpdf

然后指示PHPExcel使用它

$renderer = PHPExcel_Settings::PDF_RENDERER_MPDF;
$rendererPath = dirname(__FILE__).'/../../../libraries/PDF/mPDF6.1'

if (!PHPExcel_Settings::setPdfRenderer(
    $renderer,
    $rendererPath
    )) {
    die('Wrong setup of PDF libraries');
}

答案 1 :(得分:0)

请在DomPDF.php中对此行进行注释

if (file_exists($pdfRendererClassFile)) {
    require_once $pdfRendererClassFile;
} else {
    throw new PHPExcel_Writer_Exception('Unable to load PDF Rendering library');
}

/**  Require DomPDF library */
//$pdfRendererClassFile = PHPExcel_Settings::getPdfRendererPath() . '/dompdf_config.inc.php';
//if (file_exists($pdfRendererClassFile)) {
//    require_once $pdfRendererClassFile;
//} else {
//    throw new PHPExcel_Writer_Exception('Unable to load PDF Rendering library');
//}

希望它会起作用。