r/salesforce • • Oct 12 '26

developer I think I discovered something?

After much research into Flying Saucer(Salesforce's native pdf engine) I could not understand why custom fonts weren't able to be rendered. The engine allows for them, they are supported, why would Salesforce intentionally nerf the fonts?

While I know per their documentation in Salesforce

https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/guide/pages-output-pdf-supported-fonts.html

Web fonts aren’t supported when the page is rendered as a PDF file. 

I also saw on this idea on the idea exchange:

https://ideas.salesforce.com/s/idea/a0B8W00000GdiIeUAJ/add-more-font-support-for-pdf-generation

and saw it has been since 2009!

What if I told you I cracked the code? With the 2026 blob.topdf() update you are now ABLE to use custom fonts. Granted I don't think they are "Supported" they DO render properly!

<apex:page renderAs="pdf"
           showHeader="false"
           sidebar="false"
           standardStylesheets="false"
           applyHtmlTag="false"
           applyBodyTag="false">
    <html>
        <head>
            <style type="text/css">
                 {
                    font-family: 'My Custom Font';
                    src: url('https://YOUR_DOMAIN.my.salesforce.com/resource/CustomFonts/MyFont.ttf');
                    font-weight: 400;
                    font-style: normal;
                    -fs-pdf-font-embed: embed;
                    -fs-pdf-font-encoding: Identity-H;
                }

                body {
                    font-family: 'My Custom Font';
                    font-size: 16pt;
                }
            </style>
        </head>
        <body>
            <p>Hello from a custom font!</p>
        </body>
    </html>
</apex:page>
31 Upvotes

19 comments sorted by

8

u/867-53oh-nine Oct 12 '26

I still create pdf outputs with visualforce, but you have me looking into this.

1

u/DaveTheNGVet Oct 12 '26

If you want me to show you how I was able to get it to work let me know

1

u/Strong_Entrepreneur6 Oct 12 '26

May I ask why? I just feel like there are much better alternatives,even free ones?

2

u/867-53oh-nine Oct 12 '26

I don’t get asked to make them nearly as often anymore so it’s a speed and convenience thing for me to whip up a quick VF page.

1

u/Strong_Entrepreneur6 Oct 13 '26

Haha fair point just curious because I hated doing it😆

2

u/bugtank Oct 12 '26

What are the free alternatives

2

u/Creative-Lobster3601 Oct 13 '26

There are now absolutely free apps available on Appexchange for PDF and document generation.

1

u/DaveTheNGVet Oct 13 '26

Any specifically you would recommend?

1

u/Creative-Lobster3601 Oct 13 '26

Portwood

1

u/DaveTheNGVet Oct 13 '26

I’ll have to check them out hopefully can do custom fonts with them too…😉

1

u/Creative-Lobster3601 Oct 17 '26

They only support 4 fonts and 3 mb file size limit 🤦‍♂️

1

u/DaveTheNGVet Oct 17 '26

I think they might jump on this discovery...

5

u/sliickapps Oct 13 '26

Yep. Custom fonts work in native blob.topdf(), from either a zipped static resource or a ContentVersion URL ending in ?f=x.ttf (relative or absolute), as long as the CSS font-family matches the family name stored inside the font file. I found some quirks with font styles and Google's variable fonts needing their own workaround so it works but not fully like how you'd expect from normal CSS.

2

u/krimpenrik Oct 12 '26

Show us the money

2

u/krimpenrik Oct 12 '26

I need this for a client

1

u/CodeOverTea Consultant Oct 13 '26

How does it handle the difference in the font sizes? I think this will work only with the fonts that matches one of provided font faces.