thinkphp tcpdf乱码如何解决


这篇文章主要讲解了“thinkphp tcpdf乱码如何解决”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“thinkphp tcpdf乱码如何解决”吧! thinkphp tcpdf乱码的解决办法:1、下载插件TCPDF;2、通过“class Pdf extends appcommoncontrollerBase{…}”方式使用TCPDF;3、将字体改为“$pdf->SetFont(‘cid0cs’, ”, 8)”即可解决乱码问题。thinkphp6 生成pdf下载插件TCPDFcomposer 安装

composerrequiretecnickcom/tcpdf

官网

https://tcpdf.org/examples/

官网中有许多的例子,可根据自身的需求选择使用TCPDF

SetCreator(PDF_CREATOR);
$pdf->SetAuthor('NicolaAsuni');
$pdf->SetTitle('TCPDFExample001');
$pdf->SetSubject('TCPDFTutorial');
$pdf->SetKeywords('TCPDF,PDF,example,test,guide');
//setdefaultheaderdata
$pdf->SetHeaderData(PDF_HEADER_LOGO,PDF_HEADER_LOGO_WIDT免费云主机域名H,PDF_HEADER_TITLE.'001',PDF_HEADER_STRING,array(0,64,255),array(0,64,128));
$pdf->setFooterData(array(0,64,0),array(0,64,128));
//setheaderandfooterfonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN,'',PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA,'',PDF_FONT_SIZE_DATA));
//setdefaultmonospacedfont
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
//setmargins
$pdf->SetMargins(PDF_MARGIN_LEFT,PDF_MARGIN_TOP,PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
//setautopagebreaks
$pdf->SetAutoPageBreak(TRUE,PDF_MARGIN_BOTTOM);
//setimagescalefactor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
//setsomelanguage-dependentstrings(optional)
if(@file_exists(dirname(__FILE__).'/lang/eng.php')){
require_once(dirname(__FILE__).'/lang/eng.php');
$pdf->setLanguageArray($l);
}
//---------------------------------------------------------
//setdefaultfontsubsettingmode
$pdf->setFontSubsetting(true);
//Setfont
//dejavusansisaUTF-8Unicodefont,ifyouonlyneedto
//printstandardASCIIchars,youcanusecorefontslike
//helveticaortimestoreducefilesize.
$pdf->SetFont('dejavusans','',14,'',true);
//Addapage
//Thismethodhasseveraloptions,checkthesourcecodedocumentationformoreinformation.
$pdf->AddPage();
//settextshadoweffect
$pdf->setTextShadow(array('enabled'=>true,'depth_w'=>0.2,'depth_h'=>0.2,'color'=>array(196,196,196),'opacity'=>1,'blend_mode'=>'Normal'));
//Setsomecontenttoprint
$html=Welcometo$kid_namePDF!
ThisisthefirstexampleofTCPDFlibrary.

ThistextisprintedusingthewriteHTMLCell()methodbutyoucanalsouse:Multicell(),writeHTML(),Write(),Cell()andText().

Pleasecheckthesourcecodedocumentationandotherexamplesforfurtherinformation.

TOIMPROVEANDEXPANDTCPDFINEEDYOURSUPPORT,PLEASEMAKEADONATION!

EOD; //PrinttextusingwriteHTMLCell() $pdf->writeHTMLCell(0,0,'','',$html,0,1,0,true,'',true); //--------------------------------------------------------- //CloseandoutputPDFdocument //Thismethodhasseveraloptions,checkthesourcecodedocumentationformoreinformation. $pdf->Output('example_001.pdf','F'); return'example_001.pdf'; } }

ThistextisprintedusingthewriteHTMLCell()methodbutyoucanalsouse:Multicell(),writeHTML(),Write(),Cell()andText().Pleasecheckthesourcecodedocumentationandotherexamplesforfurtherinformation.TOIMPROVEANDEXPANDTCPDFINEEDYOURSUPPORT,PLEASEMAKEADONATION!注意:因为TCPDF使用定界符的方式输出html等内容,因此上述代码中的$html一直到EOD必须顶格。中文乱码的问题,将字体改为$pdf->SetFont(‘cid0cs’, ”, 8)即可。前端显示

感谢各位的阅读,以上就是“thinkphp tcpdf乱码如何解决”的内容了,经过本文的学习后,相信大家对thinkphp tcpdf乱码如何解决这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是百云主机,小编将为大家推送更多相关知识点的文章,欢迎关注!

相关推荐: web前端面试问答题有哪些

这篇文章主要讲解了“web前端面试问答题有哪些”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“web前端面试问答题有哪些”吧!这两个方法都可以用来判断变量类型区别:前者是判断这个变量是什么类型,后者是判断这个变量…

免责声明:本站发布的图片视频文字,以转载和分享为主,文章观点不代表本站立场,本站不承担相关法律责任;如果涉及侵权请联系邮箱:360163164@qq.com举报,并提供相关证据,经查实将立刻删除涉嫌侵权内容。

(0)
打赏 微信扫一扫 微信扫一扫
上一篇 02/26 15:53
下一篇 02/26 15:53

相关推荐