Unable to display Tamil font in TFPDF - php
I am trying to display Tamil content in PDF format using TFPDF. I have downloaded TSCu_SaiIndira.ttf, a Tamil font and stored it in the path C:\wamp\www\tfpdf\font\unifont. The Tamil word stored in Notepad is 'பெயர்கள்'. When I run the code below, it is printed with different letters
<?php
require('tfpdf.php');
$pdf = new tFPDF();
$pdf->AddPage();
// Add a Unicode font (uses UTF-8)
$pdf->AddFont('DejaVu','','TSCu_SaiIndira.ttf',true);
$pdf->SetFont('DejaVu','',14);
// Load a UTF-8 string from a file and print it
$txt = 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 12 KB.');
$pdf->Output();
?>
I am new to coding. I've read all the answers posted for the relevant questions but nothing is working out.
In this code:
$pdf->AddFont('DejaVu','','TSCu_SaiIndira.ttf',true);
$pdf->SetFont('DejaVu','',14);
You are using 'DejaVu' as the font family name, which isn't right. I did a quick test, and:
$pdf->AddFont('TSCu_SaiIndira','','TSCu_SaiIndira.ttf', true);
$pdf->SetFont('TSCu_SaiIndira','',14);
Worked for me.
Related
Dompdf Version 0.8.5 Arabic RTL Not Showing Correctly
I'm currently using the latest version of dompdf 0.8.5 , trying to export arabic text to pdf file <?php $linktentinvoice='<html><head><style>*{ font-family: DejaVu Sans, sans-serif; }</style><head><p>مرحبا</p></html>'; require_once 'dompdf/autoload.inc.php'; use Dompdf\Dompdf; // instantiate and use the dompdf class $dompdf = new Dompdf(); $dompdf->loadHtml($linktentinvoice, 'UTF-8'); // (Optional) Setup the paper size and orientation $dompdf->setPaper('A4', 'landscape'); // Render the HTML as PDF $dompdf->render(); // Output the generated PDF to Browser $dompdf->stream(); ?> The result is showing : ا ب ح ر م However the result has to be: مرحبا
The UTF-8 codes for those two Arabic strings are the same, but in the opposite order. Here's the hex: D985 D8B1 D8AD D8A8 D8A7 == ا ب ح ر م D8A7 D8A8 D8AD D8B1 D985 == مرحبا Somewhere, something is failing to understand that Arabic is "right-to-left". Suggest you get hex dumps at various steps of the processing. I believe that MySQL is not at fault. (But I can't say about the other components.)
In order to display correctly in a PDF character shaping has to be performed by the rendering engine. Dompdf (up to and including 0.8.6) does not fully support rendering of Arabic script (see issue #712). One work-around would be to perform the necessary conversion of your text prior to feeding it to Dompdf. In the issue the developer of ar-php suggests the following: require_once './ar-php/src/arabic.php'; $Arabic = new ArPHP\I18N\Arabic(); $p = $Arabic->arIdentify($html); for ($i = count($p)-1; $i >= 0; $i-=2) { $utf8ar = $Arabic->utf8Glyphs(substr($html, $p[$i-1], $p[$i] - $p[$i-1])); $html = substr_replace($html, $utf8ar, $p[$i-1], $p[$i] - $p[$i-1]); } You can then render the modified HTML content via Dompdf.
Can't import most TTF files to TCPDF
I have read all the tutorials there are to read about this topic, I simply can't make this work, neither do the example codes and online tools... When I try to import most .ttf files into TCPDF fonts, the resulting php file goes something like this: <?php $type='TrueType'; $name='FontAwesome5Free-Solid'; $desc=array('Ascent'=>875,'Descent'=>-125,'CapHeight'=>875,'Flags'=>96,'FontBBox'=>'[5000 5000 -5000 -5000]','ItalicAngle'=>-50,'StemV'=>70,'MissingWidth'=>1000); $up=-123; $ut=49; $dw=1000; $cw=array( 0=>1000,1=>1000,2=>1000,3=>1000,4=>1000,5=>1000,6=>1000,7=>1000,8=>1000,9=>1000, 10=>1000,11=>1000,12=>1000,13=>1000,14=>1000,15=>1000,16=>1000,17=>1000,18=>1000,19=>1000, 20=>1000,21=>1000,22=>1000,23=>1000,24=>1000,25=>1000,26=>1000,27=>1000,28=>1000,29=>1000, 30=>1000,31=>1000,32=>1000,33=>1000,34=>1000,35=>1000,36=>1000,37=>1000,38=>1000,39=>1000, 40=>1000,41=>1000,42=>1000,43=>1000,44=>1000,45=>1000,46=>1000,47=>1000,48=>1000,49=>1000, 50=>1000,51=>1000,52=>1000,53=>1000,54=>1000,55=>1000,56=>1000,57=>1000,58=>1000,59=>1000, 60=>1000,61=>1000,62=>1000,63=>1000,64=>1000,65=>1000,66=>1000,67=>1000,68=>1000,69=>1000, 70=>1000,71=>1000,72=>1000,73=>1000,74=>1000,75=>1000,76=>1000,77=>1000,78=>1000,79=>1000, 80=>1000,81=>1000,82=>1000,83=>1000,84=>1000,85=>1000,86=>1000,87=>1000,88=>1000,89=>1000, 90=>1000,91=>1000,92=>1000,93=>1000,94=>1000,95=>1000,96=>1000,97=>1000,98=>1000,99=>1000, 100=>1000,101=>1000,102=>1000,103=>1000,104=>1000,105=>1000,106=>1000,107=>1000,108=>1000,109=>1000, 110=>1000,111=>1000,112=>1000,113=>1000,114=>1000,115=>1000,116=>1000,117=>1000,118=>1000,119=>1000, 120=>1000,121=>1000,122=>1000,123=>1000,124=>1000,125=>1000,126=>1000,127=>1000,128=>1000,129=>1000, 130=>1000,131=>1000,132=>1000,133=>1000,134=>1000,135=>1000,136=>1000,137=>1000,138=>1000,139=>1000, 140=>1000,141=>1000,142=>1000,143=>1000,144=>1000,145=>1000,146=>1000,147=>1000,148=>1000,149=>1000, 150=>1000,151=>1000,152=>1000,153=>1000,154=>1000,155=>1000,156=>1000,157=>1000,158=>1000,159=>1000, 160=>1000,161=>1000,162=>1000,163=>1000,164=>1000,165=>1000,166=>1000,167=>1000,168=>1000,169=>1000, 170=>1000,171=>1000,172=>1000,173=>1000,174=>1000,175=>1000,176=>1000,177=>1000,178=>1000,179=>1000, 180=>1000,181=>1000,182=>1000,183=>1000,184=>1000,185=>1000,186=>1000,187=>1000,188=>1000,189=>1000, 190=>1000,191=>1000,192=>1000,193=>1000,194=>1000,195=>1000,196=>1000,197=>1000,198=>1000,199=>1000, 200=>1000,201=>1000,202=>1000,203=>1000,204=>1000,205=>1000,206=>1000,207=>1000,208=>1000,209=>1000, 210=>1000,211=>1000,212=>1000,213=>1000,214=>1000,215=>1000,216=>1000,217=>1000,218=>1000,219=>1000, 220=>1000,221=>1000,222=>1000,223=>1000,224=>1000,225=>1000,226=>1000,227=>1000,228=>1000,229=>1000, 230=>1000,231=>1000,232=>1000,233=>1000,234=>1000,235=>1000,236=>1000,237=>1000,238=>1000,239=>1000, 240=>1000,241=>1000,242=>1000,243=>1000,244=>1000,245=>1000,246=>1000,247=>1000,248=>1000,249=>1000, 250=>1000,251=>1000,252=>1000,253=>1000,254=>1000,255=>1000); $enc='cp1252'; $diff=''; $file='lol.z'; $originalsize=191836; // --- EOF --- Look that all characters are invalid, basically. This is the result I get using my PHP source, or using online converters made for TCPDF (eg.: http://www.xml-convert.com/en/convert-tff-font-to-afm-pfa-fpdf-tcpdf or http://fonts.snm-portal.com/). I am trying to add font-awesome's TTF files (eg. fa-solid-900.ttf) to my TCPDF, but I get this error. I have no idea what to do now.
You need to import FontAwesome as a Unicode font. [Also noting: Characters 0-255 will have character widths of 1000 in your example because they don't exist in this font and 1000 is the width defined for your missing glyph width.] For your other fonts that are failing, try importing them as Unicode fonts as well or with a different encoding table. //Ignore the warnings about undefined indexes on first import. //There's no H or x glyphs in the font, so the warning is expected. $fa = TCPDF_FONTS::addTTFfont('fa-solid-900.ttf', 'TrueTypeUnicode', '', 4); //Note: using empty string for $enc since this is a Unicode font //Note: using 4 for $flags to signify a symbol font. 32 for text fonts. $pdf->setFont($fa); $pdf->writeHTMLCell(100,120,40,10,""); //An example inlined with normal text: $pdf->setFont('helvetica'); $pdf->writeHTMLCell(100,120,40,20,"Should be a gamepad: <span style=\"font-family:$fa;\"></span>"); Attached screenshot of test output results: Test script: <?php //Update to your TCPDF path include 'TCPDF/tcpdf.php'; $pdf = new TCPDF('P', 'mm','Letter', true, 'UTF-8', false, true); $pdf->addPage(); $pdf->setFontSubsetting(true); $fa = TCPDF_FONTS::addTTFfont('fa-solid-900.ttf', 'TrueTypeUnicode', '', 4); $testtext = "Font name: {$fa}<br>". "Should be a gamepad: <span style=\"font-family:$fa;\"></span>"; $pdf->writeHTMLCell(100,10,10,10,$testtext); $pdf->Output(dirname(__FILE__).'/fasolid-test.pdf', 'F');
All language supporting PDF Generation using PHP
I want to generate PDF which will have Chinese and English. Literally it has to be supported in all language. I am using html2pdf, I tried many options but not working. This is my code, tried with different fonts. It takes the font but not printing correctly. Printing some spacial characters instead. $html2pdf = new HTML2PDF('P', 'A4', 'en', true, 'UTF-8'); $html2pdf->setDefaultFont('arialunicid0'); //using this line // display the full page $html2pdf->pdf->SetDisplayMode('fullpage'); // convert $html2pdf->writeHTML($content, isset($_GET['vuehtml']));
you can create other languages page in HTML and then convert that page into pdf $htmlcode = 'http://localhost:8081/kaamtrade/resume.php?userid='.$userid; $html2pdf->WriteHTML(file_get_contents($htmlcode)); i use this code in mpdf to convert whole resume html page into pdf. maybe help in your case.
Imagick annotateImage not showing correctly japanese text
I'm trying to print japanese text to the image. My code: $text = // some japanese text $imagick = new IMagick(); // $imagick implementation $imagickDraw = new ImagickDraw(); $imagickDraw->setFontSize(12); $textFontMetrics = $imagick->queryFontMetrics($imagickDraw, $text); $imagick->annotateImage($imagickDraw, ($imageWidth - $textFontMetrics['textWidth']) / 2, $imageHeight * 0.5, 0, $text); // save imageBlob When i check my generated image, instead of normal japanese text i just see '??'. Any ideas how to solve this problem?
Pretty sure this is a font related issue. Make sure you have a font capable of displaying Japanese characters, copy that font to your script's directory, and add the following: $draw->setFont('fonts-japanese-gothic.ttf'); Where fonts-japanese-gothic.ttf is the name of your font. I tested it out on my local machine and that did the trick.
tcpdf for Arabic display the characters as question marks '?????? ???'
I wanna create an Arabic pdf as same as the file witch I had in ms Execl format. While creating the pdf using tcpdf in php the Arabic charactors are displyaed as '????' marks. The characters are copied from my excel file $htmlcontent2 = '<span color="#0000ff">"مجوهرات السليمان"This is Arabic "مجوهرات السليمان" Example With TCPDF.</span>'; $pdf->WriteHTML($htmlcontent2, true, 0, true, 0); the output file display as below, ??? ???? ?????? ??????This is Arabic "??????? ????????" Example With TCPDF.
I solved this issue by adding the following line: $pdf->SetFont('aealarabiya', '', 18); It turned out that you need to set the proper font type to remove those ugly ????? characters. The exmaple mentioned in this link was very useful to solve this issue.
I solved this issue by following this step: Download TCPDF from here: http://sourceforge.net/projects/tcpdf/ Open the TCPDF file after download and go to FONTS Copy these files aealarabiya.ctg.z aealarabiya.z aealarabiya.php Paste in this location: your WHCMS root / includes/fonts if fonts folder doesn't exist create it. Go to WHCMS Admin Panel Got to WHMCS Set Up / General Setting / Invoice / TCPDF Font Family / custom (aealarabiya)
there might be issue with your character set in your code here is very good example for official TCPDF to use arabic character to write new pdf. just go throw this example with your application you can sure solve your issue. hope this will help to you.