Tamil fonts do not appear in the TCPDF php library - php

I am trying to create a pdf in the Tamil language, but I am experiencing font rendering issues. When I use the Baamini font, it works, but there is no English font in Baamini, so I tried other fonts such as latha.ttf, notosans.ttf, azaghi.ttf, and others, but these fonts do not work in tcpdf or fpdf. Please assist us in resolving this, and thank you in advance!
<?php
header('Content-type: text/html; charset=UTF-8') ;//chrome
require_once('tcpdf_include.php');
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->setFontSubsetting(true);
$pdf->SetFont('freeserif', '', 12);
$pdf->AddPage();
$utf8text = '<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> </head> <body> <p>தினமும் உங்களை இந்த தோட்டத்து வழியாக செல்லும்போது என்னை கவனிப்பீர்களா என்று திரும்பி திரும்பி பார்த்து செல்வேன். ஆனால் நீங்களோ வெறி பிடித்தது போல் மண்ணை கொத்தி கொண்டிருப்பீர்கள்.</p></body></html>';
$pdf->writeHTML($utf8text, true, 0, true, true);
$pdf->Output('example_067.pdf', 'I');
?>
My Output is

Related

dompdf local language(gujarati) text not display properly

I am using DOMPDF version 2
i want to print Gujarati text in my pdf and gujarati font is displayed but it changed some text like "ટેસ્ટ ડેટા ચેક" is changed in pdf. not all character is changed but some merraged and special character is changed. I had tried multiple different gujarati fonts but same thing is happen in all.
<?php
use Dompdf\Dompdf;
require 'vendor/autoload.php';
$html = '
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
#font-face {
font-family: "notoSerifGujarati";
src:url(fonts/NotoSerifGujarati-VariableFont_wght.ttf)
}
.m {
font-family: "notoSerifGujarati";
}
</style>
</head>
<body>
<p class="m">
ટેસ્ટ ડેટા ચેક
</p>
</body>
</html>';
$tmp = sys_get_temp_dir();
$dompdf = new Dompdf([
'logOutputFile' => '',
// authorize DomPdf to download fonts and other Internet assets
'isRemoteEnabled' => true,
// all directories must exist and not end with /
'fontDir' => $tmp,
'fontCache' => $tmp,
'tempDir' => $tmp,
'chroot' => $tmp,
]);
$dompdf->loadHtml($html); //load an html
$dompdf->render();
$dompdf->stream('hello.pdf', [
'compress' => true,
'Attachment' => false,
]);
how text displayed in pdf

Library Mpdf (php): Set utf-8 and use WriteHTML with utf-8

I need help with the php Mpdf library. I am generating content for a pdf, it is in a div tag, and sent by jquery to the php server, where Mpdf is used to generate the final file.
In the generated pdf file the utf-8 characters go wrong, for example "generación" instead of "generación".
I detail how they are implemented:
HTML
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Sending content for pdf (jquery)
$('#pdf').click(function() {
$.post(
base_url,
{
contenido_pdf: $("#div").html(),
},
function(datos) {
}
);
});
Reception content (PHP)
$this->pdf = new mPDF();
$this->pdf->allow_charset_conversion = true;
$this->pdf->charset_in = 'iso-8859-1';
$contenido_pdf = this->input->post('contenido_pdf');
$contenido_pdf_formateado = mb_convert_encoding($contenido_pdf, 'UTF-8', 'windows-1252');
$this->m_pdf->pdf->WriteHTML($contenido_pdf_formateado);
Other tested options:
1.
$this->pdf->charset_in = 'UTF-8';
Get error:
Severity: Notice --> iconv(): Detected an illegal character in input string
2.
$contenido_pdf_formateado = mb_convert_encoding($contenido_pdf, 'UTF-8', 'UTF-8');
or
3.
$contenido_pdf_formateado = utf8_encode($contenido_pdf);
Get incorrect characters, like the original case.
What is wrong or what is missing to see the text well? Thanks
Solution
$contenido_pdf_formateado = utf8_decode($contenido_pdf);
$this->m_pdf->pdf->WriteHTML($contenido_pdf_formateado);
I had used the mode on object creation
$mpdf = new Mpdf(['mode' => 'UTF-8']);
Use this if you are sure that your html is utf-8
A combination of this
$mpdf = new Mpdf(['mode' => 'UTF-8']);
and the below worked for me.
$mpdf->autoScriptToLang = true;
$mpdf->autoLangToFont = true;
the only thing you have to do to active utf-8 is to add a defult font :
i did this and worket very well so try it and let the others knows if it's a good solotion or not.
just add a defult font and see..
$mpdf = new \Mpdf\Mpdf([
'default_font_size' => 9,
'default_font' => 'Aegean.otf' ]);

PDF/A exsiting pdf with TCPDF and FPDI

Hello my task is to certify pdf with digital Signature Certification and release it in pdf/a format. I tried using tcpdf, but i couldn't import existing pages. So I added fpdi, kind of mixing them:
require_once('./tcpdf/tcpdf.php');
require_once('./tcpdf/fpdi.php');
$pdf = new FPDI( );
//$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false, true);
$file = realpath("484.pdf");
$pagecount = $pdf->setSourceFile($file);
for($i = 1 ; $i <= $pagecount ; $i++){
$tpl = $pdf->importPage($i);
$size = $pdf->getTemplateSize($tpl);
$orientation = $size['h'] > $size['w'] ? 'P':'L';
$pdf->AddPage($orientation);
$pdf->useTemplate($tpl, null, null, $size['w'], $size['h'], true);
}
$pdf->SetCreator("Creator");
$pdf->SetTitle('123Titel');
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$certificate = 'file://123.crt';
$info = array(
'Name' => '123test',
'Location' => 'place',
'Reason' => '123',
'ContactInfo' => '123',
);
$pdf->setSignature($certificate, $certificate, '123', '', 2, $info);
$pdf->SetFont('helvetica', '', 12);
$pdf->addEmptySignatureAppearance(0, 0, 0, 0);
$pdf->Output('test.pdf', 'F');
Alright, so I can put signature in alright with this, but i cant make it pdf/a.
What decides pdf/a format is
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false, true);
The last "true". But I cant use this tcpdf function, or i get:
Call to undefined method TCPDF::setSourceFile() in...
So im forced to use $pdf = new FPDI( );, which can't save pdf in pdf/a format
Surely someone knows something that im missing and im running out of ideas on what to do.
-Can I import existing pdf with only tcpdf and if yes HOW?
-Is there any other way to make file format pdf/a (i coudlnt find any)
-Any tips whatsoever
It appears that I can extend tcpdf with fpdi. Somehow it didnt work until i changed fpdi_bridge to always extend tcpdf and changed
new FPDI();
to
new FPDI(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false, true);

Render graph with tcpdf

I use PHPGraphlib to render graph and TCPDF to generate PDF report.
Now i want to render my chart on pdf file.
I have file chart.php
<?php
include("phpgraphlib.php");
$graph = new PHPGraphLib(400,300);
$data = array("Alex"=>99, "Mary"=>98, "Joan"=>70, "Ed"=>90);
$graph->addData($data);
$graph->setTitle("Test Scores");
$graph->setTextColor("blue");
$graph->createGraph();
?>
And the second file is render.html
<html>
<h3>This is where I want to display my graph</h3>
<img src="chart.php" />
</html>
My problem is how render the content of render.html in my pdf file.
Thank you
This is the solution
$pdf->Image('http://127.0.0.1/glib/examples/chart.php',60,180,0,0,'', '', '', true, 150, '', false, false, 0, false, false, false);

TCPDF UTF8 - weird spacing between characters

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?

Categories