博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PHP7.27: pdf
阅读量:6859 次
发布时间:2019-06-26

本文共 3050 字,大约阅读时间需要 10 分钟。

http://www.fpdf.org/

https://github.com/Setasign/FPDF

https://www.ntaso.com/fpdf-and-chinese-characters/

AddPage();$pdf->SetFont("Arial","B",16);$pdf->Cell(40,10,"Hello World! 涂聚文"); //中文乱码$pdf->Output();}catch(Exception $ex){ echo($ex->getMessage());}?>

  

https://www.phpbook.jp/fpdf/japan/index2.html

解决中文问题:

http://www.fpdf.org/en/script/script92.php 

把中文后缀为.tff字体文件放入至:tfpdf\font\unifont 的文夹下即可。参考 http://www.fpdf.org/en/script/script92.php 

下载:

https://dejavu-fonts.github.io/Download.html

AddPage();// Add a Unicode font (uses UTF-8)//tfpdf\font\unifont 把中文的字体文件放入其内则可。$pdf->AddFont('DejaVu','','3pdwg6wqe1jpcgh.ttf',true); //msyh.ttf 设置字体即可,字体名称不可以定义为中文 简体篆体 :3pdwg6wqe1jpcgh.ttf$pdf->SetFont('DejaVu','',14);// Load a UTF-8 string from a file and print it// 在操作系统下可以选择的字体可以显示,则也可以生成$txt ="English: Hello WorldGreek: Γειά σου κόσμοςPolish: Witaj świeciePortuguese: Olá mundoRussian: Здравствулте мирVietnamese: Xin chào thế giới,中国智造0123456789 涂聚文geovindu 生命的意义,涂聚文,中华人民共和国";// file_get_contents('HelloWorld.txt');$pdf->Write(8,$txt);// Select a standard font (uses windows-1252)$pdf->SetFont('Arial','',14);$pdf->Ln(10);$pdf->Write(5,'The file size of this PDF is only 13 KB.');$pdf->Output();?>

  

 

AddPage();// Add a Unicode font (uses UTF-8)//tfpdf\font\unifont 把中文的字体文件放入其内则可。$pdf->AddFont('DejaVu','','3pdwg6wqe1jpcgh.ttf',true); //msyh.ttf 设置字体即可,字体名称不可以定义为中文 简体篆体 :3pdwg6wqe1jpcgh.ttf$pdf->SetFont('DejaVu','',14);// Load a UTF-8 string from a file and print it// 在操作系统下可以选择的字体可以显示,则也可以生成$txt ="English: Hello WorldGreek: Γειά σου κόσμοςPolish: Witaj świeciePortuguese: Olá mundoRussian: Здравствулте мирVietnamese: Xin chào thế giới,中国智造0123456789 涂聚文geovindu 生命的意义,涂聚文,中华人民共和国";// file_get_contents('HelloWorld.txt');$pdf->Write(8,$txt);$pdf->Ln(16);$sheader=array("姓名","年龄","性别","工资","学历");$data=array();$data[0]=array("geovindu","1","男","100","");$data[1]=array("sibodu","2","男","200","");$data[2]=array("涂聚文","3","女","300","");$data[3]=array("小涂","4","女","400","");$data[4]=array("阿文","5","男","500","");$data[5]=array("小文","6","女","600","");$width=array(40,40,40,40); //设置每列宽度for($i=0;$i
Cell($width[$i],6,$sheader[$i],1);}$pdf->Ln(6);foreach($data as $row){ $pdf->Cell($width[0],6,$row[0],1); $pdf->Cell($width[1],6,$row[1],1); $pdf->Cell($width[2],6,$row[2],1); $pdf->Cell($width[3],6,$row[3],1); $pdf->Cell($width[4],6,$row[4],1); $pdf->Cell($width[5],6,$row[5],1); $pdf->Ln(6);}// Select a standard font (uses windows-1252) $pdf->SetFont('Arial','',14);$pdf->Ln(10);$pdf->Write(5,'The file size of this PDF is only 13 KB.');$pdf->Output();?>

  

AddPage();// Add a Unicode font (uses UTF-8)$pdf->AddFont('DejaVu','','DejaVuSansCondensed.ttf',true);$pdf->SetFont('DejaVu','',14);// Load a UTF-8 string from a file and print it$txt = file_get_contents('./tfpdf/HelloWorld.txt', FALSE, NULL, 20, 1400); //$pdf->Write(8,$txt);// Select a standard font (uses windows-1252)$pdf->SetFont('Arial','',14);$pdf->Ln(10);$pdf->Write(5,'The file size of this PDF is only 13 KB.');$pdf->Output();?>

  

转载地址:http://nrtyl.baihongyu.com/

你可能感兴趣的文章
DocFX生成PDF文档
查看>>
运营活动需求实现
查看>>
代理(Proxy)和反射(Reflection)
查看>>
隐藏当前Activity而不关闭
查看>>
第三百四十一节,Python分布式爬虫打造搜索引擎Scrapy精讲—编写spiders爬虫文件循环抓取内容—meta属性返回指定值给回调函数—Scrapy内置图片下载器...
查看>>
温故而知新-String类
查看>>
JS控制div跳转到指定的位置的几种解决方案总结
查看>>
《图说VR》——HTC Vive控制器按键事件解耦使用
查看>>
【Java学习笔记之十一】Java中常用的8大排序算法详解总结
查看>>
android studio使用真机测试时点击Debug调试模式时报Error running app:No target device found,点击运行模式却是启动正常的...
查看>>
洛谷 P1553 数字反转(升级版)【字符串+STL stack】
查看>>
【javascript】异步编年史,从“纯回调”到Promise
查看>>
C# WinForm开发系列 - Form/Window
查看>>
python 读取单所有json数据写入mongodb(单个)
查看>>
ZooKeeper可视化Web管理工具收集(待实践)
查看>>
linux pthread【转】
查看>>
EF基础知识小记三(设计器=>数据库)
查看>>
Mybatis系列(四):Mybatis缓存
查看>>
python中的列表、元组、数组——是不是特别容易混淆啊??
查看>>
phpmyadmin 自动登录的办法
查看>>