helvetica font not working in wkhtmltopdf - html

I have been trying to use Helvetica font while creating the pdf but the font is not reflected back in pdf.
I did some google and found some solutions but none are workable.
Tried Solution 1
I found similar thing here :
Font issue
Tried the last solution mentioned over there
workaround is to define #font-face in your css and have src link
to external host that is accessible by wkhtmltopdf
But the solution is not working.
Tried Solution 2
I also tried to use google font api, but result is still not workable.
helvetica font
here is an example
Example of custom font
Tried Solution 3
I tried doing it using css property #page.
But that also is not working.
What is the approach for a workable solution.

The easiest way to fix wkhtmltopdf's font problems is to Base64 encode the font (you can use this tool) and include it in your CSS:
#font-face {
font-family: 'Helvetica';
src: url(data:font/truetype;charset=utf-8;base64,AAEAAAATAQA...
}
This works with all fonts (including Google Fonts), and guarantees cross-platform compatibility across different machines and operating systems.

For me loading fonts from Google Fonts didn't work. And putting base64ed binary into a CSS file seems a little to much for me(Korean types are several megabytes). I'd recommend to install the fonts you need to use on the machine. For Ubuntu you can simply download fonts files from Google Fonts and copy the files in to $HOME/.fonts directory and run fc-cache command in command line to rebuild the fonts list.
$ mkdir ~/.fonts
$ copy your-font-file.ttf ~/.fonts/
$ fc-cache -fv
For a Rails application you can symlink
$ ln -s /your/app/root/assets/fonts ~/.fonts
Then you will be able to list all available fonts.
$ fc-list
Nimbus Sans L:style=Regular Italic
URW Palladio L:style=Roman
Century Schoolbook L:style=Bold Italic
Nimbus Sans L:style=Bold
URW Chancery L:style=Medium Italic
Nimbus Roman No9 L:style=Regular
Century Schoolbook L:style=Bold
Century Schoolbook L:style=Italic
Nimbus Sans L:style=Regular
....

To add to the fray, using wkhtmltopdf 0.12.1 (with patched qt) on linux this worked for me:
#font-face {
font-family: dejaSansMono;
src: url('file:///usr/share/fonts/dejavu/DejaVuSansMono.ttf');
}
I.e., specifying the path to the .ttf. Simply naming a font-family, any font-family, did not work even if it did in the browser.

expanding baxangs answer for linux (x64) users: you install the ttf font file in /usr/share/fonts/font-folder/font-name
and then in your css file use the fontname which is listed in fc-list, you don't need to use #font-face, just use the fontname in your css
example Verdana.ttf======
copy from local machine to server into /usr/share/fonts/Verdana/Verdana.ttf
fc-list to get the fontname (most likely it'll be Verdana)
Then use in your css P{ font-family: 'Verdana'}
and that's it! took me a while to get it fixed.

I had the same problem with PT Sans from google. What worked for me was the following process:
Download PT Sans from google and runt it through fontsquirrel
generator
Place the #font-face (I only used the ttf) in the css (in my case was in html
head of a php file)
Note that I did not use base64 and it worked as expected.
Hope it helps

To convert HTML to PDF by wkhtmltopdf try to avoid woff font face. Use trutype format of the Google Web Fonts with base64 encode.
Recently I tried to use a google web font from Google Web Fonts. But in browser it shows correctly but it doesn't show after converting HTML to PDF.
Then after searching lots of from web at last I found tools to encode fonts to base64 encoded format and also got CSS for #font-face.

Related

How to use downloaded fonts on MacOS and iOS?

I'm trying to use a downloaded font on MacOS and iOS in Safari. There are many war stories out there about bulletproof CSS and such, but I haven't found the correct incantation. Here's my best effort, and I've tried many variations with different quoting, casing and so on. The font is called AHRDIcons, and it's installed and working on both operating systems. That's all I need---I don't need a web font, I just want something that will work on systems that have the font already available.
#font-face {
font-family: AHRDIcons;
src: local(AHRDIcons);
src: url("AHRDIcons.ttf") format("truetype");
src: url("file:/Library/Fonts/AHRDIcons.ttf") format("truetype");
}
This works on MacOS if the page is loaded locally (as file:///Users/.../cup.html), and this is because of the 3rd src option. It doesn't work on MacOS or iOS if the file is served by http (as http://.../.../cup.html), which I would expect to work using one of the first 2 srcs. But instead there are just little squares.
Conclusion: I don't think this is possible. Maybe there are defaults writes that would permit it, or maybe the whole fingerprint-detection could be turned off, but as I continue to read about this issue here and on other sites, I haven't found anything to lead me along those lines. And not sure I would do them anyway.
I solved the problem by hosting the ttf on the server, and using a src: url("http://.../../AHRDIcons.ttf") clause in the font-face declaration.
Thanks to those who helped!
If the font is already installed on the operating system and your only users are going to be on said operating system, then you don't need to add it with font-face at all.
Double click the ttf in OSX, click the 'info preview mode' icon and check what the font's family is. Then just use that in your CSS:
Here's an example with Apple Symbols:
p {
font-family:"Apple Symbols";
}

Hot to Code Custom Font in HTML/CSS to display properly on other computers

I need help please, I'm using a Custom font for my new website design which I had to do download. On my computer website looks good with this new font. Unfortunately it is not the case for any other user who did not download this custom font.
pls see: www.vanessawiacekwebs.com
I have tried use Font Face but it does not work and I do not know why ?
Font: Marathon II; http://ufonts.com/q177208
Thank you,
You're incorrectly directly linking to the font source.
Your incorrect CSS code:
#font-face {
font-family: Marathon II;
src: url(http://ufonts.com/q177208);
}
You need to download the fonts, upload them to your file directory and then use the #font-face rule to link to font files.
A multitude of beginner's tutorials exist online: https://css-tricks.com/snippets/css/using-font-face/
There is an easy way and a hard way. The easy way is to use Google Fonts. Web Fonts were a huge PITA, and Google Fonts makes it easy.
https://www.google.com/fonts
There are other options, but after 20 years of web development, this is the only solution I use.

How to use Segoe Print font in CSS?

I'm trying to make my webpage use the font Segoe Print, which is not a default browser font. I have the ttf file though, is there any way I can employ this .ttf file so that every visitor (no matter what browser) can see the font ?
I searched and found some solutions, one was saying "Convert the font using this site"
but it gives the error:
Microsoft has requested that their font Segoe Print to be blacklisted
by the generator
So how can I use this font on my website ?
I also found a solution that suggests the following CSS rule :
#font-face
{
font-family: myFirstFont;
src: url('Segoe.ttf'),
url('Segoe.eot'); /* IE9 */
}
But, will it work in non-windows browsers? I mean, does the user have to have the ttf file in their computer, or will it be loaded from my website ?
Thanks !
You cannot, in any legal and morally acceptable way. It would be illegal and morally wrong to give advice on committing the crime that such unauthorized use would constitute.
You should thus either abandon the idea or try and find a free font, or a font that may be legally used for a fee, with characteristics sufficiently similar to the font that you want to use.
You can use Kirsle to convert your TTF font to EOT. Then you need to import three format of your font in the top of your CSS, with this format:
#font-face {
font-family: 'Segoe’;
src:url('fonts/Segoe.eot?#’) format(‘eot’),
url(‘fonts/Segoe.woff’) format(‘woff’);
url(‘fonts/Segoe.ttf’) format(‘truetype’);
}
Remeber to have the ?#, it will deceive the IE to only see the first line and download it, as other browsers can't see the first line and will download the TTF format & New browsers will download the WOFF that have a less size, so will download faster.
Simply use font-family: Segoe to change an item's font in your CSS.
Why not buy it? There are reputable sources where you can purchase a license to use this font as a web font.

Where's the font file?

I'm building a page with this font, see here: jsfiddle sample
The font is called Cursive; it's not a web-safe font. On Chrome and Firefox, it looks great. However, in IE, it doesn't show.
I'd like to use a #font-face css declaration but I'm wondering where I can find the font file for it? I assume it's already loaded on my computer somewhere; I'd like to find the files I need to them on a server.
Since the fonts we are looking at could be completely different based on what fonts we have installed on our separate machines, why not try What The Font?
Take a screenshot of the text you see and upload it to Whatthefont -- it will detect what font it is using and give you several options to download both free and paid.
From there you can include it in your css file.
Your looking for the actual font file? There are literally hundreds of free font download sites within Google's grasp. Here was my top result.
Once you have found a file you like, ftp it to your server. Then using a css #font-face to include it in your stylesheet.
The benefit of using a service like Googles font api is that it is free and fast - however, there is nothing stopping you from doing this from your own server and with your own file.
<style type="text/css">
#font-face {
font-family: "My Custom Font";
src: url(http://www.example.org/mycustomfont.ttf) format("truetype");
}
p.customfont {
font-family: "My Custom Font", Verdana, Tahoma;
}
</style>
<p class="customfont">Hello world!</p>
sample via hangy
I can't see it on my machine. But is this the one you're looking for:
http://openfontlibrary.org/font/cursive
It looks like there is an open license, so you could run it through FontSquirrel to get a nice #font-face declaration.
The font that your browser is rendering as 'Cursive' is nothing more than our old friend 'Comic Sans'.
Comic Sans
"Cursive"
Compare the two links to verify

How can I make my users automatically download the font I use for my website if they don't have it?

My website uses the font ff-clifford-eighteen-web-pro-1. I want all my text to be displayed using that font even for the users that don't have it installed on their machine.
Is it possible?
You can use the #font-face generator. It allows you to upload your fonts and it will create a nifty .zip download with CSS and all the related files you need to get your custom font working for your site.
http://www.fontsquirrel.com/fontface/generator
They also have a whole lot of licensed font-kits ready for use on your site too:
http://www.fontsquirrel.com/fontface
Another great site that allows you to "lease" licensed fonts is TypeKit.
http://typekit.com/
You can't. If the font is not on the system where the browser is, the font will not be found and cannot be loaded.
You will need to distribute the font to the client systems (if you have the licensing to do that).
Short answer: you can't
Long answer: you could, but it's not easy and not widely supported. Read this article for more information.
I use Cufon. Works great, but you also have to verify licensing.
Here is a link to A million ways to embed custom fonts (and keep typography nerds off your back)
He recommends sIFR3
With the font stored in a font folder (ex: fontFolder), you would use the #font-face generator to automatically make the user download the font so it would appear wherever on the site you specify. Below, fontFolder represents the directory (folder) where the font files live, and fontName represents the font name (sitting inside the fontFolder). If you currently have the .eot .tff .woff, and .svg variations of the font stored in the fontFolder, you can copy the below code into the top of your style sheet and replace fontFolder with your own directory's name, and replace fontName with the name of your font:
#font-face {
font-family: "fontName";
src: url('fontFolder/fontName.eot');
src: url('fontFolder/fontName.eot?#iefix') format('embedded-opentype'),
url('fontFolder/fontName.woff') format('woff'),
url('fontFolder/fontName.ttf') format('truetype'),
url('fontFolder/fontName.svg')format('svg');
}
When you're ready to use your font, just use its name:
h1 {
font-family: yourFont;
}