问题描述
我正在尝试使用PHP编程语言的tcpdf库创建pdf文件.从昨天开始尝试,但仍然得到????????
而不是北印度语字体.我试图显示这句话:
I am trying to create pdf file using tcpdf library in PHP Programming language. trying from yesterday but still getting ????????
instead of Hindi fonts.I am trying to display this sentence :
我提供了2到3种不同的北印度语字体,但仅获得了问号.如果您在tcpdf或mpdf中有使用印地语的良好示例,请指导我如何做.我也曾经在PHP文件中设置UTF-8,iso-8859-1标准,但没有任何运气.您可以在下面引用我的代码:
I have included 2 to 3 different Hindi fonts but getting only question marks only. If you have good example with Hindi language in tcpdf or mpdf please guide me how to do it. I have also used to set UTF-8, iso-8859-1 standard in PHP file but not any luck. You can refer my code below:
<?php
header('Content-Type: text/html; charset=UTF-8');
//header('Content-Type: text/html; charset=Windows-1252');
// Include the main TCPDF library (search for installation path).
require_once('tcpdf_include.php');
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 001');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 007', PDF_HEADER_STRING, array(0,64,255), array(0,64,128));
$pdf->setFooterData(array(0,64,0), array(0,64,128));
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
require_once(dirname(__FILE__).'/lang/eng.php');
$pdf->setLanguageArray($l);
}
//TCPDF_FONTS::addTTFfont('../fonts/Devanagari/Devanagari.ttf', 'TrueType', "", 32);
//TCPDF_FONTS::addTTFfont('../fonts/Agra.svg', 'TrueTypeUnicode', "", 32);
// ---------------------------------------------------------
// set default font subsetting mode
$pdf->setFontSubsetting(true);
// Set font
// dejavusans is a UTF-8 Unicode font, if you only need to
// print standard ASCII chars, you can use core fonts like
// helvetica or times to reduce file size.
$pdf->SetFont('krutidev021', '', 14, '', true);
// Add a page
// This method has several options, check the source code documentation for more information.
$pdf->AddPage();
// set text shadow effect
$pdf->setTextShadow(array('enabled'=>true, 'depth_w'=>0.2, 'depth_h'=>0.2, 'color'=>array(196,196,196), 'opacity'=>1, 'blend_mode'=>'Normal'));
// Set some content to print
$html = "प्रविष्टि कर कुल बिक्री मूल्य वेट के साथ
भार(ग्रा) टिन मात्रा(सं) भुगतान का प्रकार विवरण जारीकर्ता कार्ड";
// Print text using writeHTMLCell()
$pdf->writeHTMLCell(0, 0, '', '', utf8_encode($html), 0, 1, 0, true, '', true);
// ---------------------------------------------------------
$pdf->Output('example_001.pdf', 'I');
//============================================================+
// END OF FILE
//============================================================+
推荐答案
freesans,freesansb,freeserif,freeserifb 字体具有印地语支持,这些字体在tcpdf字体文件夹中.因此将字体设置为
freesans,freesansb,freeserif,freeserifb fonts have hindi language support, these fonts are in tcpdf font folder.So set font $pdf->SetFont('freesans', '', 12);
完整代码
<?php
// Include the main TCPDF library (search for installation path).
require_once('tcpdf_include.php');
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 018');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 018', PDF_HEADER_STRING);
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
// set some language dependent data:
$lg = Array();
$l['a_meta_charset'] = 'UTF-8';
$l['a_meta_dir'] = 'ltr';
$l['a_meta_language'] = 'hi';
$lg['w_page'] = 'page';
// set some language-dependent strings (optional)
$pdf->setLanguageArray($lg);
// ---------------------------------------------------------
// set font
$pdf->SetFont('freesans', '', 12);
// add a page
$pdf->AddPage();
// Hindi content
$htmlhindi = 'नमस्ते आप कैसे हैं';
$pdf->WriteHTML($htmlhindi, true, 0, true, 0);
// ---------------------------------------------------------
//Close and output PDF document
$pdf->Output('example_018.pdf', 'I');
//============================================================+
// END OF FILE
//============================================================+
这篇关于TCpdf印地语句子显示问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!