2016-10-07 26 views
0

我想在我的php網站中使用dompdf,並嘗試在沒有作曲者的情況下包含該庫,但我無法使其工作。如何在沒有作曲者的情況下包含dompdf

我嘗試測試的代碼是:

<?php 
include "../../plugins/dompdf/Autoloader.php"; 
$dompdf = new Dompdf(); 
$dompdf->loadHtml('hello world'); 

// (Optional) Setup the paper size and orientation 
$dompdf->setPaper('A4', 'landscape'); 

// Render the HTML as PDF 
$dompdf->render(); 
?> 

,但我得到的錯誤:

Fatal error: Class 'Dompdf' not found ...

誰能解釋我如何包括但在服務器中安裝作曲家圖書館嗎?

謝謝。

回答

3

你需要錯誤的自動載入文件。該文檔清楚地說明,包括這個文件自動加載:

require_once 'dompdf/autoload.inc.php';

如果你看一下這個文件,你會看到它確實需要Autoloader.php但執行一些其他的引導任務爲好。

+0

謝謝Samrap,你說得對。我修正了include,並給我一個php-font-lib和php-svg-lib庫的錯誤。我安裝了庫,錯誤再次出現:致命錯誤:找不到'Dompdf'類。 – Roke

+0

我忘記把「使用Dompdf \ Dompdf;」解決問題,現在正在工作。謝謝你,Samrap。 – Roke

1

隨着正確的包括工作就像一個魅力,正如所說的桑普拉我包括錯誤的文件。

現在的代碼是:

<?php 
//Configure the directory where you have the dompdf 
require_once "../../plugins/dompdf/autoload.inc.php"; 
use Dompdf\Dompdf; 
//$dompdf = new dompdf(); 
//$dompdf = new DOMPDF(); 
$dompdf = new Dompdf(); 
$dompdf->loadHtml('hello world'); 
// (Optional) Setup the paper size and orientation 
$dompdf->setPaper('A4', 'landscape'); 
// Render the HTML as PDF 
$dompdf->render(); 
// Output the generated PDF to Browser 
$dompdf->stream(); 
?> 

謝謝Samrap的幫助。

相關問題