Active2 months ago
I am using dompdf as part of a larger framework and was looking for a way to manually add a new font. Your post gave me the idea to just take out dompdf and run the installer on that and then put the entire folder back in the folder. So thank you. How to import new font (ex: Commons) in dompdf v0.7beta? The Unicode How-to has information on how to install fonts. Double-click the font in the Finder, then click Install Font in the font preview window that opens. After your Mac validates the font and opens the Font Book app, the font is installed and available for use. Using Windows 7 and 8 Installing Fonts on Windows XP and Vista Install Fonts on Mac OS Installing Fonts. How To install New Fonts on Windows.
When generating a PDF it totally ignores my
font-family
attribute applied to my CSS. Instead of say Verdana, it uses Times New Roman. So my CSS look like:The PDF is generated like this:
How can I set a font I want?
JohnJohn9797 gold badges26 silver badges58 bronze badges
6 Answers
PDF documents internally support the following fonts: Helvetica, Times-Roman, Courier, Zapf-Dingbats, & Symbol (all using Windows ANSI encoding). dompdf will embed any referenced font in the PDF so long as it has been pre-loaded or is accessible to dompdf and referenced in a CSS
@font-face
rule. The loading process is necessary in order to produce the font metrics used for type setting.dompdf supports the same fonts as the underlying R&OS PDF class: Type 1 (.pfb) and TrueType (.ttf) so long as the font metrics (.afm/.ufm) are available. The bundled, PHP-based php-font-lib provides support for loading and sub-setting fonts.
The process for loading a font varies depending on your needs and server access. There are three ways you can load a font:
- Use CSS @font-face rules to load a font at run-time.
- From the command line use dompdf/load_font.php.
- Browse to dompdf/www/fonts.php in the included admin site.
Use CSS @font-face rules to load a font at run-time
No command line access required. So long as the font you want to load is available online you can load it easily via CSS.
From the command line use dompdf/load_font.php
If you have access to the command line then loading a font is as simple as:
Run the command without any parameters to see help text. Quickly, though, the parameters are: name of the font, normal font file, bold font file, italic font file, bold-italic font file
Browse to dompdf/www/fonts.php in the included admin site
Self-explanatory (sample). The only thing you need to do is make sure you've modified the admin username/password combo
Note: load_font.php and the admin site will not be included by default starting with dompdf 0.7.0
Adapted from the dompdf wiki (Unicode How-To, About Fonts and Character Encoding) and other sources.
I have a similar problem and i have been looking a solution for 2 days...With the new version, the accepted answer does not work any more.
@jay-bienvenu answer is correct.The new version of DomPDF does not include everything and also there is a very poor documentation.
So you will have to:
- download load_font.php and place it to the root directory of yourproject:
curl -o load_font.php https://raw.githubusercontent.com/dompdf/utils/master/load_font.php
- then open load_font.php with your editor and place the correct path to your autoload.inc.php, eg
require_once 'lib/dompdf/autoload.inc.php';
- Open the command line, go to the root folder of your project, and run the utility with the name of the font you are registering and the path to the TFF fileeg
php load_font.php SourceSansPro ./pathToYourFolder/lib/dompdf/SourceSansPro-Regular.ttf ./pathToYourFolder/lib/dompdf/SourceSansPro-Bold.ttf
Now the font is installed. You may use it as you would normally would as a webfont in html:
and to make the pdf in php:
EDIT: i made a blog post about how to use dompdf and apply custom fonts so that things can be more detailed: https://www.blog.lab21.gr/using-domdpf-create-pdf-php
Mayra MMayra M
Dompdf's About Fonts and Character Encoding says the font utility is included but doesn't tell you how to get it and run it. Here's how:
- Download load_font.php to the root directory of your project.
curl -o load_font.php https://raw.githubusercontent.com/dompdf/utils/master/load_font.php
- Open load_font.php with a text editor (e.g. vim). Change
require_once 'autoload.inc.php';
torequire_once 'vendor/autoload.php';
- Run the utility with the name of the font you are registering and the path to the TFF file. For example:
php load_font.php 'Brush Script MT' https/fonts/brush-script-mt.ttf
Read the code for load_font.php for more information about how to use this command.
Jay BienvenuJay Bienvenu1,0633 gold badges16 silver badges29 bronze badges
You need to have the font loaded in DomPDF. Check this page for details.
cOle2cOle23,1111 gold badge15 silver badges21 bronze badges
Thanks for the answer by Brians above, but in my case only one option worked which is by installing font using 'dompdf/www/fonts.php'
it installed the font byBrowsing to dompdf/www/fonts.php in the included admin site. (it will be something like http://yoursite.com/sites/all/modules/print/lib/dompdf/www/fonts.php)
Go to bottom of the page, and click on a link
it comes up with alert saying 'password must be changed in dompdf_config.custom.inc.php'.
- Go to dompdf_config.custom.inc.php file and add the user name andpassword in the bottom of the file. you can find'DOMPDF_ADMIN_USERNAME' and 'DOMPDF_ADMIN_PASSWORD'. uncomment these2 lines and add user name and password for installing the font.
- Now, again click on
[Authenticate to access this section][2]
, it asks for user name and password. enter user user name and password which u have given in step one. - if you browse the same fonts.php path again in your browser you can find install new fonts section in the bottom of the page( you can see in image),(however, i moved my rockwell.ttf and rockwell.afm files to fonts folder first and then i installed here)
- choose your desired font ttf file and then install it. it installed and showing in installed fonts but it did not work for me. so I had to create to .afm file for my new font.(here i wanted to use rockwell font)
steps I did to create my rockwell.afm file. 1
I did this like dompdf other 14 native fonts, I'm not sure how acceptable is this. but it worked for me. I just wanted to get it done.
- I've added my rockwell font where ever i found the dompdf native font names in php files
- Added 'rockwell' to
public static $native_fonts
array in dompdf/include/dompdf.cls.php file - Added 'rockwell' array to
dompdf/lib/fonts/dompdf_font_family_cache.dist.php file like below
thats it. it generated rockwell.afm file for me like this
- just use whatever font family you want to use like
2,5344 gold badges28 silver badges39 bronze badges
You need to use dompdf library for generate pdf with specific font family.
RameshRamesh
Not the answer you're looking for? Browse other questions tagged phpdompdf or ask your own question.
-->Symptoms
After you install a font into the Fonts folder in the operating system and start Microsoft Word for Mac, the font unexpectedly is not available in the Font dialog box, in the drop-down list, or in the Formatting Palette.
Cause
Third-party fonts are not directly supported in Microsoft Office for Mac applications. Some third-party fonts may work in one application and not in another. Other third-party fonts are installed in a 'family'. A family usually consists of the third-party font itself together with some or all of its variations (bold, italic, and so forth). Sometimes, a font may be displayed in Microsoft Word, Microsoft PowerPoint, Microsoft Excel, or Microsoft Entourage, but you may be unable to use one of its variations, such as italic.
Office does not support custom fonts. This includes any fonts that were manipulated by a font or typography program.
Note
Microsoft Office for Mac technical support does not provide support for installing or configuring third-party fonts.
Basic font troubleshooting
If the following methods don't resolve your font issue, contact the font manufacturer or the website from which you purchased the fonts.
First, restart your computer, and then test the font again. Some installations are not complete until the computer is restarted. This also makes sure that all applications are restarted after the installation.
Method 1
How To Install New Fonts Mac
- Clear the font caches. To do this, quit all Microsoft Office applications. On the Home menu, click **Go **> Applications, and then click Appleās Font Book.
- On the Edit menu, click Select Duplicated Fonts.
- On the Edit menu, click Resolve Duplicates.
- To remove all the fonts from the computer that Font Book just disabled, follow these steps:
- After the duplicates have been resolved, select each disabled font, click File > Reveal in Finder, and then drag it to the trash.
- You may notice that Font Book sometimes turns off the newer copy of the font instead of the older one. If you prefer the newer copy, drag the older one to the trash, and then re-enable the new one.
- Restart the computer. Apple OS X will rebuild its font cache, and Word will rebuild its font cache from that.
- For best performance in Word, try to run with all your fonts enabled all the time. Each time that Word starts, it compares its font cache with the system font cache. If the two don't match, Word will regenerate its own font cache, which can take a few seconds. If you have dynamically enabled fonts, the system font cache will appear different nearly every time that Word runs this comparison.
- You must do this every time you install an update, because the Microsoft installer tries to restore the disabled fonts each time.
Method 2
Restart the computer in Safe mode. Then, restart the computer normally. For more information about how to restart your computer in Safe mode, click the following article number to view the article in the Microsoft Knowledge Base:
2398596 How to use a 'clean startup' to determine whether background programs are interfering with Office for Mac
Method 3
Create a new user account to determine whether the problem is associated with an existing user account.
Dompdf Page Numbers
The font is damaged, or the system is not reading the font
If the font is not a custom font and does not appear in your Office program, the font may be damaged. To reinstall the font, see Mac OS X: Font locations and their purposes.
Dompdf Tutorial
The third-party products that this article discusses are manufactured by companies that are independent of Microsoft. Microsoft makes no warranty, implied or otherwise, regarding the performance or reliability of these products.