0
votes

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

2
font-family: Arial, courier, sans-serif;? Or font-family: Arial, sans-serif; and font-family: courier, monospace; to use them separately. Does this work?Sebastian Simon
You could install Microsoft Fonts for Ubuntuvsnyc
@vsnyc Yeah, having the relevant fonts in your system is a good idea as well.Sebastian Simon

2 Answers

1
votes

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”).

1
votes

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.