fpdf不支持php中的utf8_general_ci collation和utf-8编码 [英] fpdf doesn't support utf8_general_ci collation and utf-8 encoding in php
问题描述
您好,
我有一个名为ddms的mysql数据库和一个名为district的表。
i我试图使用php的fpdf库以pdf格式从我的数据库中检索数据。
我的数据以utf-8编码存储,整理是utf8_general_ci。
数据是gujarati shruti字体。
但是当我运行php脚本时它会显示如下: àªà૕રત
请尽快帮助我。
我的代码是:
define('FPDF_FONTPATH','font /');
require('fpdf / fpdf.php');
包括include / db_connection.php;
//创建一个FPDF对象
$ pdf = new FPDF();
//设置整个文档的字体
$ pdf-> AddFont('Shruti','我','shruti。 php');
$ pdf-> SetFont('Shruti');
// $ pdf-> SetTextColor(50,60,100);
//设置页面
$ pdf-> AddPage('P');
$ pdf-> SetDisplayMode('default');
//插入图片并将其设为链接
$ pdf->图片('images / logo.gif',100,10,20,0);
//显示标题它周围的边框
$ pdf-> SetXY(40,30);
$ pdf-> SetDrawColor(50,60,100);
$ pdf->写(10,'假日大师',0,'C',0);
$ pdf->行(10,40,200,40);
//设置主文本的x和y位置,减小字体大小和写入内容
$ pdf-> SetXY(20,45) ;
$ pdf-> SetFontSize(10);
$ pdf-> SetTextColor(30,30,100);
包括include / db_connection.php;
$ sql =SELECT * FROM district;
$结果= mysql_query($ sql);
while($ rows = mysql_fetch_array($ result))
{
$ dnm = $ rows ['distname'];
$ pdf-> SetXY(20,60);
$ pdf-> SetFo ntSize(12);
$ pdf-> SetTextColor(0,0,0);
$ pdf->写(7,$ dnm);
$ pdf-> SetTextColor(0,0,0);
$ pdf-> Ln();
}
//输出文件
$ pdf->输出('test.pdf','I');
?>
Hello,
I have one mysql database named ddms and one table named district in there.
i am trying to retrieving data from my database in pdf using fpdf library of php.
my data is stored in utf-8 encoding and collation is utf8_general_ci.
data is in gujarati shruti font.
but whene i run php script it shows me something like this : સ૕રત
Kindly help me as soon as possible.
My code is :
define('FPDF_FONTPATH', 'font/');
require('fpdf/fpdf.php');
include "include/db_connection.php";
//create a FPDF object
$pdf=new FPDF();
//set font for the entire document
$pdf->AddFont('Shruti','I','shruti.php');
$pdf->SetFont('Shruti');
//$pdf->SetTextColor(50,60,100);
//set up a page
$pdf->AddPage('P');
$pdf->SetDisplayMode('default');
//insert an image and make it a link
$pdf->Image('images/logo.gif',100,10,20,0);
//display the title with a border around it
$pdf->SetXY(40,30);
$pdf->SetDrawColor(50,60,100);
$pdf->Write(10,'holiday master',0,'C',0);
$pdf->Line(10,40,200,40);
//Set x and y position for the main text, reduce font size and write content
$pdf->SetXY (20,45);
$pdf->SetFontSize(10);
$pdf->SetTextColor(30,30,100);
include "include/db_connection.php";
$sql="SELECT * FROM district";
$result = mysql_query($sql);
while($rows= mysql_fetch_array($result))
{
$dnm = $rows['distname'];
$pdf->SetXY (20,60);
$pdf->SetFontSize(12);
$pdf->SetTextColor(0,0,0);
$pdf->Write(7,$dnm);
$pdf->SetTextColor(0,0,0);
$pdf->Ln();
}
//Output the document
$pdf->Output('test.pdf','I');
?>
推荐答案
pdf = new FPDF();
//设置整个文档的字体
pdf=new FPDF();
//set font for the entire document
pdf-> AddFont('Shruti','我','shruti.php');
pdf->AddFont('Shruti','I','shruti.php');
pdf-> SetFont('Shruti');
//
pdf->SetFont('Shruti');
//
这篇关于fpdf不支持php中的utf8_general_ci collation和utf-8编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!