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

本文共 3102 字,大约阅读时间需要 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();?>

  

转载于:https://www.cnblogs.com/geovindu/p/9543857.html

你可能感兴趣的文章
JS DOM操作基础
查看>>
DataSet.GetBookMark内存泄漏
查看>>
get请求中params参数的使用
查看>>
[LeetCode] 617. Merge Two Binary Trees
查看>>
[LeetCode] 538. Convert BST to Greater Tree
查看>>
Django中的form模块的高级处理
查看>>
[js]DOM 篇
查看>>
C# 观察者模式
查看>>
SQLite(二)高级操作
查看>>
iOS开发之oc(二十)--Foundation(5)NSDictionary
查看>>
初入RFID技术
查看>>
电暖器选购指南(包括暖风机)
查看>>
各类常犯的错误总结
查看>>
mac打包python3程序
查看>>
Manacher's algorithm: 最长回文子串算法
查看>>
算法题003 斐波那契(Fibonacci)数列
查看>>
MySQL索引背后的数据结构及算法原理
查看>>
CSS定位 position
查看>>
冒泡排序
查看>>
es7新特性 includes用法
查看>>