To add new font Arvo in DOMPdf I updated file dompdf_font_family_cache.distand added following code -
Fonts can be installed in several folders in OS X, but we recommend that you do the following: First, close any open applications. Newly installed fonts may not appear in your font menu if you ignore this step. Install using Font Book: Double click the unzipped font file and Font Book will open a preview of the font. Save the fonts in the place you want them to go, and Font Book will create a folder with the font files for the fonts you exported. Move this folder onto your new Mac. To install the new fonts in bulk, open Font Book on the new Mac and go to File Add Fonts. Then browse to the folder you created.
I included font files in lib/fonts directoryI added style sheet in html -
But new font is not added in result pdf.Please help me to resolve this problem.
Instead of manually modifying dompdf_font_family_cache you should use load_font.php or (in dompdf 0.6.0 beta 3) the web-based installer located at www/fonts.php.
For windows with WAMP/XAMPP, etc...
C:wampwwwbinphpphp5.4.3php.exe load_font_php Consola consola.ttf
In my case, I solved it:
Installing load_font.php from here: https://github.com/dompdf/utils/blob/master/load_font.php
1.1. Create a new file in your root folder from your project and save.
1.2. Next, run this line in your command line: php load_font.php FONTNAME FONTPATH/fonts/EXAMPLEFONT.ttf
Search and open the file dompdf_font_family_cache.php and update your file in this way (eg):
Go to your PDF and use your font.
These few steps maybe solve the issue. :)
To ensure maximum compatibility you should follow all of the followingsteps. Click through for additional details.
This extension is necessary for dompdf to parse Unicode/UTF-8 textcorrectly. dompdf relies heavily on the MBString family of functionsfor parsing text. Without these functions characters could becorrupted, words split randomly, and lines wrapped in the wrong place.
Installation instructions can be found in thePHP documentation.
Note: Version 0.6.0 included a basic compatibility layer for installationswhere MBString was unavailable. This compatibility layer is no longerprovided as of version 0.7.0. If you require a compatibility layer tryPatchwork UTF-8 for PHP.
You will need dompdf 0.6.0 or greater because earlier releases do notsupport character encodings other than Windows ANSI. Find the latestrelease of dompdf on the releases page.
This requirements applies to dompdf 0.6.0 only. As of dompdf 0.7.0Unicode support is always enabled.
For dompdf to handle Unicode characters correctly you must enableUnicode support in your configuration. Edit dompdf_config.inc.php ordompdf_config.custom.inc.php so that DOMPDF_UNICODE_ENABLED
is true
.Without enabling this setting your text will be re-encoded to Windows ANSIwhen inserted into the PDF and any characters that fall outside thisencoding will be converted to question marks.
In order to display your text correctly the PDF needs access to a fontthat supports the characters used in the document. dompdf includes theDejaVu fonts, which support awide range of characters. If the DejaVu fonts do not support your thecharacters in your document any TrueType font will work.
Note: dompdf currently supports only TrueType fonts. So when lookingfor a font make sure it comes in TrueType format.
There are currently two methods available for loading a font:
Note: The load_font.php script was distributed with dompdf 0.6.x andearlier. It was removed from the distribution as of version 0.7.0.Updated versions of the file are now maintained as part of thedompdf-utils project.
load_font.php relies on php-font-libto extract the information dompdf needs to use a font. If you followed thedompdf installation instructions you should already have this library.
load_font.php is a command-line script, it can not be run through yourweb server. The script accepts the following parameters:
Run load_font.php without any parameters to see the help text.
All you need to successfully install a font is the normal variant.
As an example, say we have a font named Firefly located at/home/fonts
. To install this font you would go into your dompdfinstallation directory and enter the following command:
which would produce the following output:
So long as the font you want to load is accessible to dompdf you canload it easily via CSS.
This page can be found at dompdf/www/fonts.php. You must modifythe admin username/password combo in your configuration before youcan upload a new font.
The admin site is no longer distributed with dompdf as of version 0.7.0.
For dompdf to correctly parse your document you must let it know whatencoding is used. To do this place a meta tag in the head of yourdocument that specifies the encoding. We recommend encoding documents toUTF-8 for greatest compatibility. However, you should be able to use otherencodings so long as the computer where dompdf is installed supports thespecified encoding.
You should also ensure that your html editor is using the encoding youhave specified. If, for example, you specify that your document is usingUTF-8 but your editor is actually encoding your document in iso-8859-5,then there is a chance that the text of the document will be mangled. Anexception to this rule is that entity-encoded characters should beaccurately parsed regardless of the document encoding.
In an earlier example we loaded the Firefly font into our DOMPDFinstallation. Here is a sample document that uses that font:
When you style a block of text to display using a specific font that fontmust support all the characters in that block. Any character notsupported will typically show up as an unfilled square. DOMPDF does notattempt to find a replacement font for unsupported characters.