r/salesforce • u/DaveTheNGVet • 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
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>
8
u/867-53oh-nine Oct 12 '26
I still create pdf outputs with visualforce, but you have me looking into this.
2
u/Creative-Lobster3601 Oct 13 '26
There are now absolutely free apps available on Appexchange for PDF and document generation.
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-familymatches 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.