嗨,我在我的应用程序中使用 tcpdf,对此我有两个问题。当我单击指定按钮时,我能够获得 html 页面的 pdf 输出。我的第一个问题是:当我单击该按钮时,如何下载该 html 的 pdf 输出?($pdf->lastPage() 不起作用)。我的第二个问题是:如何为 Trkish 设置字符编码?(我使用的是 dejavusans,但一些土耳其字符显示为问号)
谢谢提前...
对于输出,您应该查看示例:http ://www.tecnick.com/public/code/cp_dpage.php?aiocp_dp=tcpdf_examples
我不建议将字符编码设置为土耳其语。我建议改用 utf8。(dejavusans 不是将其编码为字体)
<?php
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// create your PDF
$pdf->Output(); // This will Output the PDF to the Browser if a Plugin is installed or download the PDF file if not
您必须为按钮创建表单,然后在提交按钮上发布该表单。请参见下面的代码。
<br>
<?php<br>
if($_POST['download'])<br>
{<br>
$strPdfName = “Myfile”; <br>
<br>
include(“pdf/tcpdf.php”); <br>
<pre>
$strHtml='write here html';
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, ‘UTF-8′, false); <br>
$pdf->setPrintHeader(false); <br>
$pdf->AddPage(); <br>
$pdf->SetFont(‘helvetica’, ”, 9); <br>
$pdf->writeHTML($strHtml, true, 0, true, 0); <br>
$pdf->lastPage();<br>
$pdf->Output($strPdfName, ‘D’);<br>
}<br>
?>