2014-06-30 34 views
2

我正在使用DOMPDF從HTML生成PDF。 我已經從github(編碼分支)複製了所有必需的文件。但它說類DOMPDF沒有錯誤,如下所示。在gitbubPHP致命錯誤:在第30行找不到類「DOMPDF」

鏈接dompdf_config.inc.php:https://github.com/dompdf/dompdf/tree/encoding

這裏是我的代碼:

require_once("APIs/dompdf-encoding/dompdf_config.inc.php");  
$cart_body='<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>New Order Placed</title></head><body><p>Test Printing...</p></body></html>'; 
     $dompdf = new DOMPDF(); 
     $dompdf->load_html($cart_body);//body -> html content which needs to be converted as pdf.. 
     $dompdf->render(); 
     $dompdf->stream("sample.pdf"); //To popup pdf as download 

實際產量:

Fatal error: Class 'DOMPDF' not found in /home/web/www/test_dompdf.php on line 30

線30 $dompdf = new DOMPDF();

備註:其他主分公司工作正常。我需要這個編碼分支,因爲它解決了與字體相關的編碼問題。

回答

5

我測試了你的代碼,它適用於我 - sample.pdf文件正在瀏覽器中下載。我從https://github.com/dompdf/dompdf/releases/tag/v0.6.1 URL下載庫(不僅是編碼分支(

也許你沒有移動整個項目選定的目錄或者你還沒有下載整個圖書館。我搬到了整個下載目錄內容APIs/dompdf-encoding目錄,我這裏有文件dompdf_config.inc.php和目錄libincludewww

編輯

當您編輯只希望用編碼分支,你必須做在BEG中添加以下代碼文件的局:

use Dompdf\Adapter\CPDF; 
use Dompdf\Dompdf; 
use Dompdf\Exception; 

EDIT2

整個工作代碼:

<?php 
use Dompdf\Adapter\CPDF; 
use Dompdf\Dompdf; 
use Dompdf\Exception; 



     require_once("APIs/dompdf-encoding/dompdf_config.inc.php");  
$cart_body='<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>New Order Placed</title></head><body><p>Test Printing...</p></body></html>'; 
     $dompdf = new Dompdf(); 
     $dompdf->load_html($cart_body);//body -> html content which needs to be converted as pdf.. 
     $dompdf->render(); 
     $dompdf->stream("sample.pdf"); //To popup pdf as download 

我也以防萬一改變DOMPDFDompdf(在Windows兩者都工作)

+0

供應商文件夾在哪裏?我沒有看到任何東西 – logan

+0

你需要安裝Composer並使用它。如果我將DOMPDF_ENABLE_AUTOLOAD設置爲False,那麼簡單看一下'http:// getcomposer.org/doc/00-intro.md' url,如上面的註釋DomPDF示例 –

+0

那麼我不需要安裝自動加載? – logan

相關問題