看板 PHP 關於我們 聯絡資訊
如題 : 我使用TCPDF的套件包 , <?php require_once('tcpdf/tcpdf.php'); require_once('tcpdf/config/lang/eng.php'); $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); $pdf->SetFont('cid0jp', '', 10); $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); $pdf->AddPage(); 假設設置純HTML語法 $html = <<<EOF <body>HELLO</body> EOF; //使用 $pdf->write(36,$html); $pdf-> Output("example.pdf", "I"); //輸出結果 會變成 <body>HELLO</body> //使用 $pdf->writeHTML($html); $pdf-> Output("example.pdf", "I"); //輸出結果 會變成 HELLO /* Q : 請問一下我如何 讓 */ $font = 'HELLO'; $html = <<<EOF <body><?echo $font;?></body> EOF; $pdf->writeHTML($html); $pdf-> Output("example.pdf", "I"); /* 輸出結果變成 HELLO 呢 ? 也就是說 , 我需要參雜 PHP撈資料庫的值 寫入 HTML 語法 讓TCPDF可以順利輸出 含PHP變數的HTML的PDF頁面? 假設有資料庫 DB_NAME = change_pdf , DB_TABLE_NAME = change_table DB_FIELD_NAME = id , name , company ,假設已連上DB */ include 'db.php'; $sql = "select `company` from `change_table` where `id`='1' and `name`='andy'"; $result = mysql_query($sql); $row = mysql_fetch_row($result); $context = $row[0]; // company 假設為 -> IBM $html = <<<EOF <html><body><?echo $context;?></body></html> EOF; //請問如何讓他輸出成 " company " 文字 . 麻煩知道的幫小弟解惑一下 , 感謝 . ?> -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.135.7.28
taichunmin:使用 Heredoc 方式指定的資料,仍可使用$符號來指定變 08/28 13:13
taichunmin:數, 就連 {$data} 的方式也可使用, 你可將其想成雙引 08/28 13:13
taichunmin:號指定文字的使用方法。 08/28 13:13
taichunmin:詳見 http://php.net/manual/en/language.types.string 08/28 13:13
taichunmin:.php 08/28 13:13
taichunmin:補網址 http://ppt.cc/euxP 08/28 13:23
sktdeity:感謝 , 已解決 !! 08/28 13:47
sktdeity:t大 , 請問有辦法將 php echo 出來的html 用tcpdf 呈現嗎 08/28 15:04
sktdeity:有辦法像google 的列印功能一樣將整個頁面轉成PDF? 08/28 15:20
taichunmin:簡單的方法 直接使用 file_get_contents 來抓到目標網 08/28 22:36
taichunmin:頁,再餵給 TCPDF 即可。 08/28 22:37
taichunmin:如果是伺服器端想要把目前產生的東西弄成PDF,就要用 08/28 22:38
taichunmin:ob_start 配合 ob_get_contents 來取得已經 echo 出的 08/28 22:39
taichunmin:內容,但是此法需要在前面使用 ob_start 08/28 22:39
sktdeity:謝謝t大 , 我在try看看 !! 08/29 09:29
sktdeity:t大 , 我使用ob_start 及 ob_get_contents 是順利取得 08/29 10:29
sktdeity:html或是php 檔 , 把他存下來 , 在餵給tcpdf , 不過畫面 08/29 10:30
sktdeity:還是沒辦法像google 列印那樣整個頁面轉成pdf , 格式都跑 08/29 10:30
sktdeity:掉 , 沒辦法像echo 出來餵給tcpdf的 writeHTML($html); 08/29 10:31
twsphere:tcpdf 很多css ..會失敗.. 08/29 12:09
sktdeity:可能要改用wkhtmltopdf了 ... 08/29 12:10
sktdeity:我有用過wkhtmltopdf , 不過目前只測試成功灌在windows 08/29 14:00
sktdeity:上面的installer.exe 去cmd下指令 , 套件包還沒測~ 08/29 14:00