8

Trying to use a custom font in my visualforce page (rendered as pdf). I have looked at many conflicting articles saying that the only option are the "limited" fonts supported, whereas others say that you can add the css as a static resource and reference (https://developer.salesforce.com/forums?id=906F000000096dcIAA bottom comment).

Does anyone know if this is possible/had success with custom fonts before?

  • did you try ? Often that's quite a good way to discover what's possible and what's not. – Samuel De Rycke Oct 21 '14 at 9:59
  • No I haven't tried it, didn't want to waste company time on a wild goose chase. It's just that I was getting very mixed responses when researching ("it's not possible / it should be possible / try using css as a static resource, etc.). Thanks though – Justin Oct 21 '14 at 16:01
11

The current v31.0 "official" line is that there is a limited set of fonts available.

Fonts Available When Using Visualforce PDF Rendering

Visualforce PDF rendering supports a limited set of fonts. Use the following font names to ensure that PDF output renders as you expect.
The fonts available when you’re rendering a page as a PDF are as follows. The first listed font-family value for each typeface is the recommended choice.

  • Typeface

    • Style font-family Value to Use (Font Synonyms)
  • Arial Unicode MS

    • Arial Unicode MS
  • Helvetica
    • sans-serif
    • SansSerif
    • Dialog
  • Times
    • serif
    • Times
  • Courier
    • monospace
    • Courier
    • Monospaced
    • DialogInput

Note

  • These rules apply to server-side PDF rendering. You might see different results when viewing pages in a web browser.
  • Text styled with any value besides those listed above receives the default font style, Times. This means that, ironically, while Helvetica’s synonyms render as Helvetica, using “Helvetica” for the font-family style renders as Times. We recommend using “sans-serif”.
  • Arial Unicode MS is the only multibyte font available, providing support for the extended character sets of languages that don’t use the Latin character set.

Source - Fonts Available When Using Visualforce PDF Rendering

Note also that there is talk of a new and improved PDF rendering engine in the works. This may give you better font options, but is only in closed pilot last time I checked.

| improve this answer | |
5

Assuming the PDF generation in Salesforce is based on Flying Saucer, the Flying Saucer FAQ includes an example of how to embed a custom font:

@font-face {
        font-family: "UbuntuMono";
        src: url("UbuntuMono-R.ttf");
        -fs-pdf-font-embed: embed;
        -fs-pdf-font-encoding: Identity-H; 
}

* {
        font-family: "UbuntuMono";
}

which suggests it is possible. You would need to use a public URL for the font or a static resource URL.

But I have not tried it.

PS

Just spent 30 minutes trying to get this to work for a Google font and while it works well for the HTML output I could not get it to work for PDF output. So either by design or accident it looks like this does not work in Salesforce.

| improve this answer | |
  • 3
    I've had a similar thought before, but never actually tried it in practice. Thinking about it more, I'd be surprised if the Salesforce PDF rendering engine would pull in a random font resource from the internet. How would they know they could trust the URL? – Daniel Ballinger Oct 21 '14 at 2:11
  • 1
    I am having the same use case and want to use custom font on pdf page, while running the page in html mode, it works, but in renderAs="pdf", not working. My code is this @font-face { font-family: "FuturaBT-Light"; src: url('{!URLFOR($Resource.FuturaFont, 'Futura_Corporate.ttf')}') format('truetype'); } – Ankuli May 17 '16 at 8:03
  • "The font used on the page must be available on the Visualforce PDF rendering service. Web fonts aren’t supported." Visualforce PDF Rendering Considerations and Limitations – Peter W May 29 '19 at 1:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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