I have a script which converts HTML to PDF. On Windows, it runs just fine.

But when I run the script on Ubuntu, the Arial and Courier fonts do not work correctly.

I presume this is because those fonts don't come with Ubuntu by default. That's fine, it's not a big deal.

I'm just wondering what I should change the following to, such that it will still work on Windows and use a font that is close to Arial and Courier respectively on Ubuntu?

            font-family: "Arial";
            font-family: courier;

Thanks

share|improve this question
1  
font-family: Arial, courier, sans-serif;? Or font-family: Arial, sans-serif; and font-family: courier, monospace; to use them separately. Does this work? – Xufox May 1 '15 at 4:10
    
You could install Microsoft Fonts for Ubuntu – vsnyc May 1 '15 at 4:18
    
@vsnyc Yeah, having the relevant fonts in your system is a good idea as well. – Xufox May 1 '15 at 4:19
up vote 1 down vote accepted

For the Arial-esque font use

font-family: Arial, sans-serif;

and for the Courier-esque font use

font-family: Courier, monospace;

These rules basically mean: take the first one if available, otherwise the next one, otherwise repeat until the end. It should work in normal CSS (not sure about your particular implementation, though).

sans-serif and monospace are browser or system dependent values for fonts that have been specified as those font classes (e. g. “DejaVu Sans” and “Ubuntu Mono”).

share|improve this answer
    
How can I test if sans-serif and monospace are installed on my Ubuntu? I tried the CSS change but there is no difference. It continues to use whatever the default font for Ubuntu is. – b85411 May 1 '15 at 4:44
    
As I said, sans-serif and monospace are not fonts but the default font as configured in the browser or the system. For example sans-serif could be configured to be DejaVu Sans or Ubuntu or whatever; then either of those fonts is selected automatically and the selected fonts are guaranteed to be installed (if not all fonts are deleted from the system). – Xufox May 1 '15 at 4:47
    
Oh okay. How can I find out what the list of fonts I have installed is? (I only have command line access) - then I can pick one specifically? – b85411 May 1 '15 at 4:51
    
@b85411 I’m not sure about that, unfortunately… – Xufox May 1 '15 at 5:20

One way is to use Web Safe fonts. Here's a list of Web Safe fonts you can use: CSS Web Safe Fonts

Another way can be to use a font from your web directory or fonts available on the web from services like Google Fonts,etc.

Here's its usage:

@font-face {
    font-family: fontName;
    src: url('/font/xyz.woff');
}

Check here for reference on font face rules.

Check this for getting started with Google Fonts.

Check this page for the Font Stack, showing the compatibility of fonts with different OS.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.