iT邦幫忙

0

TCPDF如何修改才可以顯示中文字型

請教各位大大,小弟我下載最新TCPDF資料,想說要如何修改才可以顯示中文字.
我參考許多網站修改了 tcpdf目錄底下example_038.php在裡頭增加了

$pdf->SetFont('msungstdlight', '', 20);     這一行   

但是輸入中文字型還是一直顯示????
請問要如何修改,順便說明我正在寫PHP網頁,不知道MySQL資料庫設為charset=big5會不會影響字型輸出.

看更多先前的討論...收起先前的討論...
丹尼 iT邦研究生 4 級 ‧ 2016-08-27 08:07:30 檢舉
http://www.mrmu.com.tw/2011/07/25/php-tcpdf-utf-8-pdf-report/
我記得資料庫讀建立時不都設定UTF-8
你現在的問題是不是,網站出現亂碼還是出現不了中文字。
fillano iT邦超人 1 級 ‧ 2016-08-27 08:49:15 檢舉
除非有特殊需要,不然請盡量使用UTF-8。big5有先天的問題。
感謝回答我在看看
fillano iT邦超人 1 級 ‧ 2016-08-27 10:10:36 檢舉
我試了一下沒問題耶?如果你的php原始碼檔是使用big5編碼,請你改用utf-8看看。
請問大大Ubuntu系統沒有安裝最新Adobe Reader是否無法正常顯示TCPDF,又或則是我php指向TCPDF檔案路徑不正確?
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

1
fillano
iT邦超人 1 級 ‧ 2016-08-29 13:24:24
最佳解答

我也只是範例照抄XD,我只是用了composer來安裝。

安裝tcpdf:

> composer install tecnickcom/tcpdf

測試程式:

<?php
require "vendor/autoload.php";//因為用composer安裝

// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 002');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');

// remove default header/footer
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);

// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

// set some language-dependent strings (optional)
/*if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
        require_once(dirname(__FILE__).'/lang/eng.php');
            $pdf->setLanguageArray($l);
}*/

// ---------------------------------------------------------

// set font
$pdf->SetFont('msungstdlight', '', 20);

// add a page
$pdf->AddPage();

// set some text to print
$txt = <<<EOD
TCPDF Example 002

Default page header and footer are disabled using setPrintHeader() and setPrintFooter() methods.
我踏月色而來。
EOD;

// print a block of text using Write()
$pdf->Write(0, $txt, '', 0, 'C', true, 0, false, false, 0);

// ---------------------------------------------------------

//Close and output PDF document
$pdf->Output('test1020.pdf', 'I');

只改了一點東西...

跑出來的樣子:
http://ithelp.ithome.com.tw/upload/images/20160829/20000108AMrgnx1CgD.png

問題已解決感謝您的回覆.

我要發表回答

立即登入回答