I've this problem with my code.
I'm trying to get the spanish special chars with accents and the "ñ" and "€".
That's my code:
include_once(PLUGINS_PATH . "tcpdf/tcpdf.php");
$pdf = new TCPDF("L", PDF_UNIT, PDF_PAGE_FORMAT, false, 'ISO-8859-1', false);
// Deshabilitando la cabecera
$pdf->setPrintHeader(false);
// Deshabilitando el pie de página
$pdf->setPrintFooter(false);
// Márgenes
$pdf->SetMargins(5, 5, 5);
// Saltos de página automáticos.
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
// Establecer el ratio para las imagenes que se puedan utilizar
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
// Establecer la fuente
$pdf->SetFont('times', 10);
// Añadir pána
$pdf->AddPage();
$pdf->writeHTMLCell(0, 0, 2, 2, $html, 0);
//Cerramos y damos salida al fichero PDF
return $pdf->Output($pdf_path_name, 'F');
the $html variable contains all the information and when I display with a simple echo $html it well encoded.
I give you one pic with my PDF.
http://img706.imageshack.us/img706/9451/kw97.png
Solved the problem displaying european simbols.
But why I'm getting those "??????" simbols?
I give you another pic
http://img51.imageshack.us/img51/6342/42th.png
PD: I've been looking for one solution for 3 days and no solution i've found.
You have specified ISO-8859-1 which is more commonly known as Latin-1. Latin-1 does include those characters. But you should specify your coalition/encoding to be UTF-8 which will likely cover all of the special characters you need.
After reading some of the documentation, it doesn't appear that they use the ISO standards to identify the different types of encoding, but it isn't clear.
$pdf = new TCPDF("L", PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
Related
This question already has answers here:
TCPDF UTF-8 symbols not showing up
(16 answers)
utf8_encode function purpose
(4 answers)
Closed 1 year ago.
I cannot see German characters correctly in the generated pdf. Here is my code:
<?php
// Load autoloader (using Composer)
require __DIR__ . '/vendor/autoload.php';
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetPrintHeader(false);
$pdf->AddPage();
// create some HTML content
$html = '<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
Die angeführten Preise sind Fixpreise für eine schlüsselfertige Ausführung gemäß Leistungsbeschreibung und Ausstattungsliste
und gelten bei einem Vertragsabschluss bis 31.12.2021.<br/>
Die m²-Angaben sind Cirka-Maße. Geringfügige Abweichungen sind möglich und auf Grundrissvarianten oder technische
Änderungen, behördliche Vorschriften etc. zurückzuführen.<br/>
In den oben genannten Preisen sind sämtliche in vorliegender Preisliste angeführten Kaufnebenkosten (mit Ausnahme der
Beglaubigungskosten und Barauslagen im Zusammenhang mit der Eintragung im Grundbuch) enthalten, der Verkauf erfolgt
provisionsfrei direkt vom Bauträger. Kosten im Zusammenhang mit der Finanzierung (insbesondere auch Kosten für die
Bankgarantie) sind von der Käuferseite zu tragen.
</body>
</html>';
$pdf->writeHTML(utf8_encode($html), true, false, true, false, '');
$pdf->lastPage();
$lastPage = $pdf->getPage();
$pdf->Output('generated.pdf', 'I');
And that's how it looks:
Looks all good on html though
just changed
$pdf->writeHTML(utf8_encode($html), true, false, true, false, '');
to
$pdf->writeHTML(($html), true, false, true, false, '');
and it worked!
You need to change the constructor, Set UTF-8 false and change new charset like below:
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, false, 'ISO-8859-1', false)
In above example, I set encoding ISO-8859-1 instead of UTF-8 and I change true to false.
header('Content-type: text/html; charset=utf-8');
in addition to be really sure the browser understands, add a meta-tag:
I need add to pdf different symbols, but sometime it get wrong result like this:
Original text is 'Sorry für die Stille'
How can I solve this?
Font settings:
$pdf = new TCPDF('L', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetFont (PDF_FONT_NAME_MAIN, '', 9 , '', 'default', true );
I am facing problem to generate japanese text based pdf using TCPDF. Previously I was working in raw php, html and css and tcpdf was working just fine with the following code:
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
if (#file_exists(APPPATH . 'libraries/tcpdf/examples/lang/eng.php')) {
require_once(APPPATH . 'libraries/tcpdf/examples/lang/eng.php');
$pdf->setLanguageArray($l);
}
if (#file_exists(APPPATH . 'libraries/tcpdf/examples/lang/jpn.php')) {
require_once(APPPATH . 'libraries/tcpdf/examples/lang/jpn.php');
$pdf->setLanguageArray($l);
}
$pdf->setLanguageArray($l);
$pdf->setPrintHeader(false);
$pdf->setFontSubsetting(true);
$pdf->SetFont('cid0jp', '', 11);
$pdf->AddPage();
$pdf->writeHTML($html, true, false, true, false, '');
$pdf->Output('result.pdf', 'I');
which can generate my desired pdf with japanese text.
氏名
(全角・名字と名前の間に字スペー
ス)
Name
(Last Name/First name)
But when I tried to include this in codeigniter controller, the japanese texts are showing question marks in the generated pdf:
require_once(APPPATH . 'libraries/tcpdf/tcpdf.php');
The pdf output becomes like the following:
??
(?????????????????)
Name
(Last Name/First name)
What I am missing? Can anybody give me a solution? I will greatly appreciate a help here.
You can try any one from listed (because I'm not sure which one works for you):-
1) $pdf->SetFont('kozgopromedium', '', 11);
2) $pdf->SetFont('kozminproregular', '', 11);
3) $pdf->SetFont('cid0jp', '', 11);
4) $pdf->SetFont('arialunicid0', '', 11);
5) $pdf->SetFont('arialuni', '', 12);
If you have font file(.ttf) in your system, then you can give path also like :-
$pdf->addTTFfont('path/myfont.ttf', '', '', 11);
I am trying to generate PDF using TCPDF with Hindi Unicode characters. I tried Mangal, Noto Sans, Arial Unicode fonts but all give the same output. If there is a "Matra" or "Half character" then it does not display properly.
See this output:
<?php
error_reporting(E_ALL);
ini_set("display_errors", "On");
require_once 'vendor/autoload.php';
$hindi_str = "राष्ट्रपति प्रणव मुखर्जी। ";
$hindi_str2 = "देश हमें देता है सब कुछ";
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
//$fontname_kannada = TCPDF_FONTS::addTTFfont('NotoSansKannada-Regular.ttf', 'TrueTypeUnicode', '', 96);
$fontname_hindi1 = TCPDF_FONTS::addTTFfont('NotoSansDevanagari-Regular.ttf', 'TrueTypeUnicode', '', 96);
$fontname_hindi2 = TCPDF_FONTS::addTTFfont('mangal.ttf', 'TrueTypeUnicode', '', 96);
$fontname_hindi3 = TCPDF_FONTS::addTTFfont("ARIALUNI.TTF", 'TrueTypeUnicode', '', 96);
// use the font
$pdf->AddPage();
$pdf->SetFont($fontname_hindi3, '', 14, '', false);
$pdf->writeHTML("<h1>Hindi $hindi_str $hindi_str2</h1>",true, false, true, false, '');
$pdf->Ln();
$pdf->writeHTML("<h1>Kannada ಖುತುಬ್ ಮಿನಾರ್ ಸಮೀಪವಿರುವ ಪ್ರಸಿದ್ಧ ಕಬ್ಬಿಣದ ಕಂಬ ಯಾರಿಗೆ ಸೇರಿದೆ</h1>",true, false, true, false, '');
// output the HTML content
// ---------------------------------------------------------
//Close and output PDF document
$pdf->Output('example.pdf', 'I');
Please help.
I know it's a little late, but I had the same problem for nepali (which also uses devanagari). I solved it like this:
// SOME FONTS DOES NOT SUPPORT DEVANAGARI, BUT FREESANS DOES
$pdf->SetFont('freesans', '', 10);
// MAKE ARRAY WITH UTF LANGUAGE IDENTIFIER
$lg = Array();
$lg['a_meta_charset'] = 'UTF-8';
$lg['a_meta_dir'] = 'ltr';
$lg['a_meta_language'] = 'np'; // I think you can change this to HI or IN for hindi
$lg['w_page'] = 'page';
// CHANGE SETTINGS IN TCPDF
$pdf->setLanguageArray($lg);
// MAKE SURE TO USE WriteHTML() function
$pdf->WriteHTML($yourhtml, true, 0, true, 0);
You can use this if Hindi is not showing on TCPDF
$pdf->SetFont('freesans', '', 10);
$lang = Array();
$lang['a_meta_charset'] = 'UTF-8';
$lang['a_meta_dir'] = 'ltr';
$lang['a_meta_language'] = 'IN';
$lang['w_page'] = 'page';
$pdf->setLanguageArray($lang);
$pdf->WriteHTML($html, true, 0, true, 0);
Pls have a look at the following picture http://dev.mosaicware.pl/tmp/PDF-utf-problem.png
As you can se PL and RO characters are looking weird, they look fine on the webpage. Any clue?
I've used arialunicid0 font and following code (characters in DB are UTF-8):
$pdf = new models_PdfUtf(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', true);
$pdf->SetFont('arialunicid0'); $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
$pdf->SetAuthor($problem . ' ' . $problem['user_surname']); $pdf->SetTitle($problem['problem_title']);
$pdf->SetSubject($problem['problem_title']);
$pdf->Output('export.pdf','I');
$pdf = new models_PdfUtf(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', true);
$pdf->SetFont('arialunicid0');
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
$pdf->setPrintFooter(false);
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
$pdf->AddPage();
$pdf->writeHTML($c, true, 0, true, 0);
$pdf->SetAuthor($problem . ' ' . $problem['user_surname']);
$pdf->SetTitle($problem['problem_title']);
$pdf->SetSubject($problem['problem_title']);
$pdf->Output('export.pdf','I');
Unfortunately, the picture is now password protected, but from your description I'd guess that there is something in the HTML. I encountered a behavior as described by cou with links. Could you check if $c contains any links at all?