DOMPDF Chinese Character - php

I have problem that when I download the PDF it will download the font together in the PDF which will create a very big size of PDF (about 10mb+).
<?php
include "/dompdf_config.inc.php";
$html =
'<html><body><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style>
*{ font-family: simsun; }
</style>
<p>开发人员指南</p>
</body></html>';
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("hello.pdf"); ?>

You'll want to enable font subsetting.
In dompdf 0.6.2 or earlier set the DOMPDF_ENABLE_FONTSUBSETTING configuration constant to true. Configuration constants can be set in dompdf/dompdf_config.custom.inc.php.
In dompdf 0.7.0 or later after you instantiate dompdf you can configure this option using the set_option method: $dompdf->set_option('isFontSubsettingEnabled', true);.

follow the procedure to use chinless language support in laravel latest version
clone https://github.com/dompdf/utils
download font from i use simsun https://www.wfonts.com/font/simsun
3.1.keep those file in project root folder
3.2 add folder name font in storage folder
Run php load_font.php "Simsun" Simsun.ttf from your comment pomp
5.then use in html body { font-family: 'Simsun'; } for chines language
6.i attach image so that it will help you

Related

Create pdf which content html and gujarati text in Laravel

I have try to create pdf in Laravel.
Usebarryvdh/laravel-dompdf vendor package class.
My pdf content English and Gujarati text.
but gujarati content print as ?????? in pdf.
I have create pdf succesfully use this type of code
pdfview is my pdf php, html content file view
view()->share('data',$data);
$pdf = PDF::loadView('pdfview');
return $pdf->stream('pdfview.pdf');
// return $pdf->download('pdfview.pdf');
I have expected to pdf content as English and Gujarati text content.
Actual result in pdf Gujarati content print like ????
use wkhtmltopdf, make sure to install all unicode library related to Gujarati language. I tried it for sinhala in ubuntu and centos.
"????" is because the font in not there by default in barryvdh/laravel-dompdf package.
1.You need to download the fonts that supports gujrati.
2.After downloading, just put the the .ttf file to your font assets folder.
3.Then use the css #font-face to explicitly declare your font supporting the gujrati characters.
Just for example (using simhei.ttf). FYI, this is in my template.blade.php file
<style type="text/css">
#font-face {
font-family: SimHei;
src: url('{{base_path().'/public/report_assets/'}}fonts/simhei.ttf') format('truetype');
}
* {
font-family: SimHei;
}
</style>
<body>
//gujrati characters
.......
Thats it

I Can't Find dompdf_config.inc.php or dompdf_config.custom.inc.php for setting "DOMPDF_UNICODE_ENABLED" true

I use dompdf to save a html page as pdf by php. I use Persian characters in my html page (actually php page) but when i'm trying to save it as pdf, the export just looked like '?????' :( .I have searched all the net and I found a configuration for unicode characters https://github.com/dompdf/dompdf/wiki/UnicodeHowTo#configure-dompdf-for-unicode-support in "dompdf_config.inc.php" or "dompdf_config.custom.inc.php" file. but the problem is I CAN'T FIND such file in all of my dompdf folder and in all of my file system. Please somebody tell me where it is or what I must do. something else is that I have to use dompdf because of its fantastic CSS compatibility. Thanks.
This is Export.
http://i.stack.imgur.com/nYAzW.png
This is my code.
require("dompdf/autoload.inc.php");
use Dompdf\Dompdf;
$dompdf = new Dompdf();
$dompdf->loadHtml("<html><head>
<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\">
<link rel=\"stylesheet\" type=\"text/css\" href=\"styles/scorestyle.css\">
</head>
<body><div>
<div id=\"showscorediv\"><table><tbody><tr class=\"scoresubject\"><th colspan=\"2\">کارنامه ارزیابی</th></tr><tr class=\"scorecategory\"><th>شاخص ها</th><th>امیتاز ها</th></tr><tr><td><span class=\"level_0\">شاخص های کیفی</span></td><td class=\"scoretd\">62</td></tr><tr><td><span class=\"level_1\">شاخص های مرتبط با تیم کاری</span></td><td class=\"scoretd\">10</td></tr><tr><td><span class=\"level_1\">شاخص های مرتبط با محصول</span></td><td class=\"scoretd\">28</td></tr><tr><td><span class=\"level_1\">شاخص های مرتبط با بازار</span></td><td class=\"scoretd\">24</td></tr><tr><td><span class=\"level_0\">شاخص های کمی</span></td><td class=\"scoretd\">60</td></tr><tr><td><span class=\"level_1\">شاخص های تولیدی</span></td><td class=\"scoretd\">20</td></tr><tr><td><span class=\"level_1\">شاخص های درآمدی</span></td><td class=\"scoretd\">14</td></tr><tr><td><span class=\"level_1\">شاخص های هزینه ای</span></td><td class=\"scoretd\">26</td></tr><tr class=\"scoresubject\"><th>امتیاز کل</th><th>122</th></tr></tbody></table>
</div>
</div></body></html>");
$dompdf->setPaper('A4', 'landscape');
$dompdf->render();
$dompdf->stream();
You appear to be using dompdf 0.7.0, which no longer uses the dompdf_config.inc.php configuration file. Unicode support is always enabled with this release.
To display the characters used in your sample code you need to ensure that:
You are supplying a font that supports these characters (that appears to be the case).
That dompdf has both read and write capability to the temporary directory, font directory, and font cache directory. You can set these using $dompdf->set_option('option', 'value'); (where option would be tempDir, fontDir, or fontCache).
The font is accessible to dompdf and is in TTF format.
You are correctly styling your content to use your font. Hard to know without seeing your CSS.
FYI, you can't just drop the TTF/UFM in your font directory. dompdf has to record information about the font in order to use it. Also, the AFM metrics file won't work in this case anyway because that indicates Windows ANSI encoding on the font. Windows ANSI encoding does not support the characters in your sample. Dompdf uses the UFM metrics format for Unicode support.
The utilities that were included with previous versions of dompdf are no longer included with 0.7.0. So long as you meet the requirements of using the #font-face declaration you don't need any external utilities. If needed, however, you can find a compatible version of the load_font.php script in the dompdf-utils project.
Since you are using 0.7.0 (which was just released) a lot of info on the Internet may be out of date, so you may want to read up on how to use it:
dompdf README
dompdf 0.7.0 release notes
dompdf wiki (pay attention to any versioning information)
Lastly, dompdf includes a font (DejaVu) that can support your characters. Try adding the following to your stylesheet so that you have a fallback in case your custom font doesn't work:
* { font-family: BZar_0, DejaVu Sans, sans-serif; }
I just added dompdf_config.inc.php and dompdf_config.custom.inc.php files from dompdf 0.6.2 version, besides include dir with autoload.inc.php and functions.inc.php to my dompdf 0.8.* and it works.
To set any DOMPDF option you have to define a named constant.
All available options can be found here: http://pxd.me/dompdf/www/setup.php
To enable Persian characters you basically have to enable unicode support.
define("DOMPDF_UNICODE_ENABLED", true);
You may want to set DOMPDF_FONT_DIR and DOMPDF_DEFAULT_FONT as well, just to make sure that the font you're using supports unicode characters.

#font-face or custom font does not work in PHP pdf generator class

I am using dompdf to generate PDFs from inputs.
The code I use:
require_once (STYLESHEETPATH.'/dompdf/include/autoload.inc.php');
set_include_path(STYLESHEETPATH.'/dompdf');
require_once STYLESHEETPATH.'/dompdf/dompdf_config.inc.php';
$dompdf = new DOMPDF();
$html = '
<html>
<body>
<h1>Hello <i>'. $fullname.'</i> </h1>
<p> your father is <b>'.$fathername.'</b>
</body>
</html>';
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("tck.pdf"); ?>
This works very fine and generates a pdf called tck.pdf
Now I want to style the fonts in the pdf so I've tried
require_once (STYLESHEETPATH.'/dompdf/include/autoload.inc.php');
set_include_path(STYLESHEETPATH.'/dompdf');
require_once STYLESHEETPATH.'/dompdf/dompdf_config.inc.php';
$dompdf = new DOMPDF();
$html = '
<html>
<head>
<style>
#font-face {
font-family: "Open Sans";
font-style: normal;
font-weight: 400;
src: url(http://themes.googleusercontent.com/static/fonts/opensans/v8/cJZKeOuBrn4kERxqtaUH3aCWcynf_cDxXwCLxiixG1c.ttf) format("truetype");
}
</style>
</head>
<body>
<h1>Hello <i>'. $fullname.'</i> </h1>
<p> your father is <b>'.$fathername.'</b>
<br/>
<span style="font-family:webfontregular;">bar code will be here</span>
<div style="font-family:"Open Sans";">Open Sans</div>
</body>
</html>';
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("tck.pdf"); ?>
But it does not work and giving an error as follow :
Fatal error: Class 'Font' not found in /home4/q0i4l0g2/public_html/tck/wp-content/themes/kallyas-child/dompdf/include/font_metrics.cls.php on line 356
I've noticed that whenever I use "#font-face" I am getting this error.
Why is that?
How can I make it work?
As per the accepted answer in this question Dompdf and set different font-family this should work I think but it does not.
When using dompdf versions prior to 0.7.0 you should not include the autoloader directly. This is done as part of the setup process performed when you include the dompdf_config.inc.php file. That setup process defines a number of constants used by dompdf as well references the autloaders for dompdf and the various libraries is uses (including php-font-lib).
If the dompdf class is already available the startup script will exit without doing anything.
Also potentially relevant is how you got dompdf. If you did not download a packaged release (i.e. you downloaded the various libraries separately) make sure you grab php-font-lib 0.3.x, the version used by the dompdf 0.6 releases.

I am trying to create malayalam pdfs using FPDF. font using meera.ttf It is working but is not working

I am trying to create malayalam pdfs using FPDF.
Font using meera.ttf
It is working but is not working correctly.
Result is like this ഇഗലീഷ്
I want the result ഇംഗ്ലീഷ്
codes***
$pdf = new tFPDF();
$pdf->AddPage();
// Add a Unicode font (uses UTF-8)
$pdf->AddFont('meera','','meera.ttf',true);
$pdf->SetFont('meera','',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('meera','',14);
$pdf->Ln(10);
$pdf->Write(5,'The file size of this PDF is only 12 KB.');
$pdf->Output();
?>
HelloWorld.txt
ഇംഗ്ലീഷ്
i got answer, use mpdf,
fpdf and tcpdf not support.
go to
https://mail.google.com/mail/u/0/?shva=1#sent/143096e2010c4a58
download ful version of mPDF v5.7 Full installation - Download (.ZIP file 12.8MB)
run example /example29_multilingual_autofont.php
eg. localhost/MPDF57/examples/example29_multilingual_autofont.php
I found the Solution.
Just Download mpdf 6.0 and use the following Query
<?php
include('mpdf.php');
$html = '
<html>
<head>
<style>
body {background-image:url(image.jpg); background-image-resize:6;}
footer {page-break-after: always;}
</style>
</head>
<body>
<p >ഇംഗ്ലീഷ്</p>
<p style="font-family:Courier New">Malayalam</p>
</body>
</html>';
$mpdf=new mPDF('ml');
$mpdf->WriteHTML($html);
$mpdf->Output();
?>

Custom Fonts for DOMPDF

I'm Using DOM PDF 0.6.0 Beta 2. I want to use custom fonts (Fonts: 'Segeo Print', 'Lucida Handwriting','Airplanes in the Night Sky') in PDF file.
I followed the guidelines to install and use fonts in my PHP Code, which is given here http://code.google.com/p/dompdf/wiki/CPDFUnicode
But I'm not able to get desire fonts in my PDF. You can find my code in this post. Please Let me know how I can resolve this issue.
<?php
require_once("dompdf_config.inc.php");
$html = "<html>
<head>
<meta http-equiv='Content-Type' content='text/html;charset=utf-8'>
<style>
*{font-size:15px;}
div.ClJ{font: nightsky;}
</style>
</head>
<body>
<div class='ClJ'>This text is in DIV Element</div><br /><br />
</body>
</html>";
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$pdf = $dompdf->output();
$dompdf->stream("dompdf_out.pdf", array("Attachment" => false));
?>
go to your DOMPDF folder
copy your font's as .ttf (TrueType Font) or .otf (OpenType Font) into the DOMPDF's root
open your command line and run php load_font.php your_fonts_name ./your-normal.ttf ./your-bold.ttf ./your-bold-italic.ttf
DOMPDF now created Adobe Font Metrics and copied it to lib/fonts/* - you can now use it with font-family: your_fonts_name;
you can add css font :
#font-face {
font-family: new_font;
src: url('my_font.ttf');
}
and than
div.ClJ{
font-family: new_font;
}
If you want to install custom fonts to the server without a command-based interface
then you can do the following web-based model to install the custom fonts
Download ejaz.php from here
Put this file to the root of dompdf and follow the instruction written in it
no need for root or command/terminal access

Categories