In latest web development industry document conversion from one format to other format is very important. Sometimes we need to generate spread sheet files, some times we need to generate word files and some times PDF files. In this topic I will be talking about PDF file conversion.
For generating PDF files from the given data, there are a number of scripts and modules written in php and different languages. DomPDF is one of them written in php. DomPDF is fabulous in its features. It allows direct conversion of HTML files to PDF files. But there are some limitations like some times it never generates the exact copy of that HTML. Some times font-family doesn't apply correctly as we apply in HTML file. I had the same problem last days when I was using DomPDF for my PDF generation. I goggled the web and found some solutions. And on the basis of those many solutions and posts, I wrote a summarized article focusing on this problem.
It need some simple steps to follow,
- Download archive from approved answer. Extract files
/dompdf/lib/fonts/times*.*
.
- Copy them in your dompdf fonts folder.
- Edit
dompdf_font_family_cache.dist.php
with snippet 1.
- In CSS use
font-family: times;
.
Snippet 1:
/* ... */
'times' => array (
'normal' => DOMPDF_FONT_DIR . 'times',
'bold' => DOMPDF_FONT_DIR . 'timesbd',
'italic' => DOMPDF_FONT_DIR . 'timesi',
'bold_italic' => DOMPDF_FONT_DIR . 'timesbi'
),
'times-roman' => array (
'normal' => DOMPDF_FONT_DIR . 'times',
'bold' => DOMPDF_FONT_DIR . 'timesbd',
'italic' => DOMPDF_FONT_DIR . 'timesi',
'bold_italic' => DOMPDF_FONT_DIR . 'timesbi'
),
/* ... */
If you want to use your own TTF font (say,
Arial.ttf
):
- Run:
ttf2afm -o Arial.afm Arial.ttf
. (I did it in Ubuntu.)
- Run:
ttf2ufm -a -F Arial.ttf
. (you can use /dompdf/lib/ttf2ufm/bin/ttf2ufm.exe
.)
- Copy
Arial.*
files in /dompdf/lib/fonts/
.
- Add to
dompdf_font_family_cache.dist.php
snippet 2.
- In CSS use
font-family: arial;
.
Snippet 2:
/* ... */
'arial' => array (
'normal' => DOMPDF_FONT_DIR . 'Arial',
'bold' => DOMPDF_FONT_DIR . 'Arial',
'italic' => DOMPDF_FONT_DIR . 'Arial',
'bold_italic' => DOMPDF_FONT_DIR . 'Arial'
)
/* ... */
Please feel free to post you comments and suggestions.
Thanks