Create pdf which content html and gujarati text in Laravel - php

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

Related

DOMPDF Chinese Character

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

domPDF create an empty PDF with custom font

I using domPDF and I' trying to add a custom font (neosans).
I use dompdf/www/fonts.php to add my font into domPDF. .ufm and .ttf files were created. I used a online convert to create .afm file and I put it in the fonts folder.
The font name is added into dompdf_font_family_cache.dist.php and dompdf_font_family_cache.php.
In CSS (<style> tag in the document) I set :
font-family: neosans;
but when I display the PDF the font is blank.
If I set Arial it's ok.

Export php file output to PDF file (Hebrew output)

Im tried to export the output of my php file.
For example, I have this php file:
<?php
echo "שלום!";
?>
I tried the tcpdf class, in the expamples folder there is a file that crate pdf with html code, the example 61 or 6 here.
The problem is when I try to take the html output by file_get_content and the content is in Hebrew the content of the pdf is "???????" or somthing like this.
Any idea how I can export my hebrew output to pdf?
I also tried fpdf and others libraries and I didn't succeed.
Help please.
Thanks
font-family: firefly, DejaVu Sans, sans-serif;
Use this font-family attribute on your hebrew letter contain element.
Do yourself a favor - use snappy to create PDF from HTML, unlike dompdf it supports all languages, directions etc.
(The package itself is just a wrapper, it uses an external library - wkhtmltopd to create the pdf).
It will render pretty much anything in any language, Hebrew included -
https://github.com/KnpLabs/snappy

How to add TTF font to html2pdf PHP program

I'm trying to use HTML2PDF 4.03 with this code:
<?php
$content = "..."; # my HTML code
require_once(dirname(__FILE__).'/html2pdf_v4.03/html2pdf.class.php');
$html2pdf = new HTML2PDF('P','A4','en', true, 'utf-8', array(15,20,15,20) );
# here I'm trying to add my arial.ttf
$html2pdf->pdf->AddTTFFont('arial.ttf');
$html2pdf->WriteHTML($content);
$html2pdf->Output('exemple.pdf');
?>
Now the program die with this:
PHP Fatal error: Call to undefined method HTML2PDF_myPdf::AddTTFFont()
How can I add TTF font to my PDF file?
I have managed to add 1 custom font to my setup using the following method.
First convert the .ttf file to 3 separate files (.php .z and .ufm) using the following
font converter
Place the 3 files that are generated by this system into the fonts folder in TCPDF.
Now you can set the default font for your PDF using the following command
$html2pdf->setDefaultFont("the_name_you_called_your_font");
This was fairly simple to get working, I am having issues using 2 seperate fonts though via this method. I'll figure it out though
To expand on the selected answer (by o11y_75) when you convert your fonts, you need to use a specific name to include also the bold and italic variants.
That way, you only add one font definition like this
$html2pdf->AddFont('opensans', 'normal', 'opensans.php');
$html2pdf->setDefaultFont('opensans');
When you convert the fonts, name them, for example, like these:
default: opensans
bold: opensansb
italic: opensansi
bold italic: opensansbi
notice that behind the original name, you add b, i and bi on each case.
I have found no documentation on this issue, but I followed the nomenclature found on the fonts that already came with TCPDF and it worked.
If you want to add multiple fonts, just use :
$html2pdf->addFont('opensansregular', '', 'opensansregular');
$html2pdf->addFont('opensansbold', '', 'opensansbold');
I would suggest that you don't use special chars with the font converter specified above.
Then in your CSS simply type :
<style type="text/css">
<!--
.uppercase {
text-transform: uppercase;
}
* {
font-family: opensansregular;
}
h1, h2, h3, strong {
font-family: opensansbold;
}
-->
</style>
HTML2PDF works internally with TCPDF.
TCPDF has its own object since version 6.2.6 to create the fonts needed for HTML2PDF: TCPDF_FONTS
I have solved this as follows:
I searched for TCPDF in the vendor directory and found the Fonts directory there.
Then I created my own separate PDF script and used it once to create the necessary font files from the ttf.
usage: $fontname = TCPDF_FONTS::addTTFfont('vendor/tecnickcom/tcpdf/fonts/arialuni/arialuni.ttf', 'TrueTypeUnicode', '', 32);
For more details see: https://stackoverflow.com/a/70337995/2320007

Making text bold or larger in dompdf

I just started using dompdf v0.6.0beta3 and the dompdf Codeigniter helper with Codeigniter. I have copied the Arial font family tff files from Windows 7 font folder to dompdf's /lib/fonts folder.
Problem: When I select a text using CSS and apply the font-weight: bold property, on the HTML output it is indeed bold, but after converting to PDF via dompdf, the text is no longer in bold!
font-size: 24px does not work, all text in the pdf are the same sizes. And the only font being used in the pdf appears to be Times New Roman!
How can I make my text bold and change its size and font in the pdf?
PHP (Controller)
function pdf() {
$this->load->model('resume_model');
$results = $this->resume_model->get_resume_details($user_id);
$this->load->helper(array('dompdf', 'file'));
$html = $this->load->view('resume_pdf', $results, true);
pdf_create($html, 'filename');
}
Is your stylesheet external to your HTML content? If so you may just have a path problem. The plugin appears to use $dompdf->load_html() to load the document. DOMPDF has no knowledge of your website when used in this way and will work off the local file system. What this means for you is that file paths are relative to the currently-executing file. If the path is absolute (e.g. /css/main.css) then DOMPDF will look for this file off the root of the file system. Instead of looking for the file at /wwwroot/content/css/main.css it will look for /css/main.css.
The quickest fix, if this is your problem, would be to add a full URL, including domain, to your file references (e.g. http://example.com/css/main.css).

Categories