php dompdf 使用

來源:互聯網
上載者:User

標籤:style   http   使用   sp   on   檔案   div   bs   ad   

新版本DOMPDF安裝
版本是6 測試版


DOMPDF下載:
https://github.com/dompdf/dompdf


php-font-lib下載:
https://github.com/PhenX/php-font-lib


1. 新版的DOMPDF似乎預設沒有php-font-lib, 下載完之後放到dompdf\lib\php-font-lib目錄中.




2. 檢查/安裝新的字型, 中文字型推薦使用Google的DroidSansFallback, 只有3MB多.
(1) 安裝字型前修改一下dompdf_config.inc.php設定檔中的
    def("DOMPDF_ADMIN_USERNAME", "yourname");
    def("DOMPDF_ADMIN_PASSWORD", "yourpassword");
使用者名稱,是安裝字型時要的。


(2) 檢查一下dompdf_config.inc.php中是否包含php-font-lib的路徑配置, 請確認系統能找到Font.php
    require_once(DOMPDF_LIB_DIR . "/php-font-lib/src/FontLib/Font.php");
加到設定檔中。


(3) 瀏覽器進入dompdf/www/fonts.php進行字型安裝
四種字型,正常的,粗體,斜體,等,一個個安裝。

include ‘dompdf6/dompdf_config.inc.php‘;


$html = <<<END


END;


 $html = file_get_contents(‘pdf.html‘);
 上面多種方法引用模板。


// $html =
  // ‘<html><body>‘.
  // ‘<p>Put your html here, or generate it with your favourite ‘.
  // ‘templating system.<br />再看一下支援中文否?</p>‘.
  // ‘</body></html>‘;
  
$dompdf = new DOMPDF();
// $dompdf->load_html(utf8_decode( $html ), ‘UTF-8‘);
$dompdf->load_html( $html, ‘UTF-8‘);
// $dompdf->load_html( $html, ‘GBK‘);
$dompdf->render();
$dompdf->stream("sample.pdf");


如果 中文不支援,為中文加上字型定義:
在HTML 範本中。
<span style="font-size:16.0pt;line-height:105%;font-family:droidsans">


如果出現沒自動換行的中文,用DIV 試試。對 table 支援不好。

php dompdf 使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.