iT邦幫忙

0

PHP如何將頁面轉成PDF

php
chan15 2010-10-04 12:07:4331090 瀏覽

目前網路上找到的library都是如何製作畫出PDF
不知道有沒有套件是可以把頁面內容直接轉成PDF的

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 個回答

5
fillano
iT邦超人 1 級 ‧ 2010-10-04 13:40:59
最佳解答

也許可以參考這個:
http://blog.sd.idv.tw/archives/286
不過他需要額外安裝,所以在虛擬伺服器大概沒辦法用。

另外之前有聽朋友講過TCPDF:
http://www.tecnick.com/public/code/cp_dpage.php?aiocp_dp=tcpdf
他有一些方法可以把html轉成pdf,但不是整頁...

看更多先前的回應...收起先前的回應...

好像較麻煩的是顯示中文的問題,
不然,一定有很多種的解決方案。
另外要在pdf隨便寫文字是單純的事、
不曉得使用很長一段中文段落時,
能不能自動地「折行」?
好像想在 pdf 中畫 table,
不曉得是不是很麻煩?
這些是在ruby畫出中文pdf時,
會碰到的問題,
所以不知php下畫是否無這些疑慮?

fillano iT邦超人 1 級 ‧ 2010-10-05 15:32:05 檢舉

我上次看朋友展示,他表格是用html語法丟給tcpdf做出來的...表單也都是中文,我乍看之下是沒看到問題啦。不過他的應用是報價單,文字一般都不是非常長,所以折行的效果就不知道了。

chan15 iT邦新手 3 級 ‧ 2010-10-06 13:49:08 檢舉

我現在正在測試tcpdf,可以請教fillano他怎麼把順利顯示中文的嗎?

chan15 iT邦新手 3 級 ‧ 2010-10-06 14:34:09 檢舉
<pre class="c" name="code"><?php
require_once('pdf/tcpdf.php');

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

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

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

// create some HTML content
$html = file_get_contents('pdf_i.php');

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

// output the HTML content
$pdf->writeHTML($html, true, 0, true, true);

// reset pointer to the last page
$pdf->lastPage();

//Close and output PDF document
$pdf->Output('test.pdf', 'I');
?>
chan15 iT邦新手 3 級 ‧ 2010-10-06 14:35:46 檢舉

目前我已經將程式碼簡潔成上方內容,但不知道為什麼秀出來的PDF會有一段黑線
http://www.tecnick.com/pagefiles/tcpdf/example_001.pdf
就像官方example header下的那條黑線

chan15 iT邦新手 3 級 ‧ 2010-10-06 18:28:53 檢舉
6
yogo
iT邦新手 3 級 ‧ 2010-10-05 13:55:25

希望下面那篇文章對你能有幫助

[PHP] 免費好用的 PDF Library 大搜集
http://blog.yogo.tw/2009/09/php-pdf-library.html

我要發表回答

立即登入回答