PHP7.27: pdf
http://www.fpdf.org/
https://github.com/Setasign/FPDF
https://www.ntaso.com/fpdf-and-chinese-characters/
<?php // 1.8.1 //define("FPDF_FONTPATH","font/"); try { require("../fpdf.php"); $pdf = new FPDF(); $pdf->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
下载: http://www.fpdf.org/en/script/dl.php?id=92&f=zip
https://dejavu-fonts.github.io/Download.html
<?php // Optionally define the filesystem path to your system fonts // otherwise tFPDF will use [path to tFPDF]/font/unifont/ directory // define("_SYSTEM_TTFONTS", "C:/Windows/Fonts/"); tFPDF //http://www.fpdf.org/en/script/script92.php require('tfpdf/tfpdf.php'); $pdf = new tFPDF(); $pdf->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 World Greek: Γειά σου κόσμος Polish: Witaj świecie Portuguese: Olá mundo Russian: Здравствулте мир 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(); ?>
<?php // Optionally define the filesystem path to your system fonts // otherwise tFPDF will use [path to tFPDF]/font/unifont/ directory // define("_SYSTEM_TTFONTS", "C:/Windows/Fonts/"); tFPDF //http://www.fpdf.org/en/script/script92.php require('tfpdf/tfpdf.php'); $pdf = new tFPDF(); $pdf->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 World Greek: Γειά σου κόσμος Polish: Witaj świecie Portuguese: Olá mundo Russian: Здравствулте мир 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<count($sheader);$i++) { $pdf->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(); ?>
<?php // Optionally define the filesystem path to your system fonts // otherwise tFPDF will use [path to tFPDF]/font/unifont/ directory // define("_SYSTEM_TTFONTS", "C:/Windows/Fonts/"); require('tfpdf\tfpdf.php'); $pdf = new tFPDF(); $pdf->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(); ?>
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)