Skip to content

Commit 1dd47bf

Browse files
RefaerdsToriLindsaykathayl
authored
[Browser Rendering] Custom font usage example (#25421)
* [Browser Rendering] Custom font usage example * Fixed error * Update supported-fonts.mdx need to update with link to below for custom * Update supported-fonts.mdx * Update src/content/docs/browser-rendering/reference/supported-fonts.mdx Co-authored-by: ToriLindsay <[email protected]> * Update supported-fonts.mdx add link to custom font section in first section * Update src/content/docs/browser-rendering/reference/supported-fonts.mdx Co-authored-by: ToriLindsay <[email protected]> * Update supported-fonts.mdx wording and header level changes * [Browser Rendering] upd custom font usage examples --------- Co-authored-by: ToriLindsay <[email protected]> Co-authored-by: Kathy <[email protected]>
1 parent 783bf01 commit 1dd47bf

File tree

1 file changed

+138
-36
lines changed

1 file changed

+138
-36
lines changed

src/content/docs/browser-rendering/reference/supported-fonts.mdx

Lines changed: 138 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@ title: Supported fonts
44
sidebar:
55
order: 3
66
---
7+
import { Tabs, TabItem } from "~/components";
78

8-
Browser Rendering uses a managed Chromium environment that includes a standard set of fonts. When you generate a screenshot or PDF, text is rendered using the fonts available in this environment.
9+
Browser Rendering uses a managed Chromium environment that includes a standard set of fonts. When you generate a screenshot or PDF, text is rendered using the fonts available in this environment.
910

10-
If your webpage specifies a font that is not supported yet, Chromium will automatically fall back to a similar supported font. If you would like to use a font that is not currently supported, reach out to us on [Cloudflare Discord](https://discord.cloudflare.com/).
11+
If your webpage specifies a font that is not supported yet, Chromium will automatically fall back to a similar supported font. If you would like to use a font that is not currently supported, you can [add a custom font](/browser-rendering/reference/supported-fonts/#use-your-own-custom-font).
1112

12-
## Generic CSS font family support
13+
## Pre-installed fonts
14+
15+
The following sections list the fonts available in the Browser Rendering environment.
16+
17+
### Generic CSS font family support
1318

1419
The following generic CSS font families are supported:
1520

@@ -19,43 +24,140 @@ The following generic CSS font families are supported:
1924
- `cursive`
2025
- `fantasy`
2126

22-
## Common system fonts
23-
24-
- Andale Mono
25-
- Arial
26-
- Arial Black
27-
- Comic Sans MS
28-
- Courier
29-
- Courier New
30-
- Georgia
31-
- Helvetica
32-
- Impact
33-
- Lucida Handwriting
34-
- Times
35-
- Times New Roman
36-
- Trebuchet MS
37-
- Verdana
27+
### Common system fonts
28+
29+
- Andale Mono
30+
- Arial
31+
- Arial Black
32+
- Comic Sans MS
33+
- Courier
34+
- Courier New
35+
- Georgia
36+
- Helvetica
37+
- Impact
38+
- Lucida Handwriting
39+
- Times
40+
- Times New Roman
41+
- Trebuchet MS
42+
- Verdana
3843
- Webdings
3944

40-
## Open source and extended fonts
45+
### Open source and extended fonts
4146

42-
- Bitstream Vera (Serif, Sans, Mono)
43-
- Cyberbit
44-
- DejaVu (Serif, Sans, Mono)
45-
- FreeFont (FreeSerif, FreeSans, FreeMono)
46-
- GFS Neohellenic
47-
- Liberation (Serif, Sans, Mono)
48-
- Open Sans
49-
- Roboto
47+
- Bitstream Vera (Serif, Sans, Mono)
48+
- Cyberbit
49+
- DejaVu (Serif, Sans, Mono)
50+
- FreeFont (FreeSerif, FreeSans, FreeMono)
51+
- GFS Neohellenic
52+
- Liberation (Serif, Sans, Mono)
53+
- Open Sans
54+
- Roboto
5055

51-
## International fonts
56+
### International fonts
5257

5358
Browser Rendering includes additional font packages for non-Latin scripts and emoji:
5459

55-
- IPAfont Gothic (Japanese)
56-
- Indic fonts (Devanagari, Bengali, Tamil, and others)
57-
- KACST fonts (Arabic)
58-
- Noto CJK (Chinese, Japanese, Korean)
59-
- Noto Color Emoji
60-
- TLWG Thai fonts
61-
- WenQuanYi Zen Hei (Chinese)
60+
- IPAfont Gothic (Japanese)
61+
- Indic fonts (Devanagari, Bengali, Tamil, and others)
62+
- KACST fonts (Arabic)
63+
- Noto CJK (Chinese, Japanese, Korean)
64+
- Noto Color Emoji
65+
- TLWG Thai fonts
66+
- WenQuanYi Zen Hei (Chinese)
67+
68+
## Use your own custom font
69+
70+
If a required font is not pre-installed, you can inject it into the page at render time using `addStyleTag`. This allows you to load fonts from an external URL or embed them directly as a Base64 string.
71+
72+
<Tabs> <TabItem label="JavaScript" icon="seti:javascript">
73+
Example with puppeteer and a CDN source:
74+
75+
```js
76+
const browser = await puppeteer.launch(env.MYBROWSER);
77+
const page = await browser.newPage();
78+
await page.addStyleTag({
79+
content: `
80+
@font-face {
81+
font-family: 'CustomFont';
82+
src: url('https://your-cdn.com/fonts/MyFont.woff2') format('woff2');
83+
font-weight: normal;
84+
font-style: normal;
85+
}
86+
87+
body {
88+
font-family: 'CustomFont', sans-serif;
89+
}
90+
`
91+
});
92+
```
93+
94+
</TabItem> <TabItem label="TypeScript" icon="seti:typescript">
95+
Example with puppeteer and a CDN source:
96+
97+
```ts
98+
const browser = await puppeteer.launch(env.MYBROWSER);
99+
const page = await browser.newPage();
100+
await page.addStyleTag({
101+
content: `
102+
@font-face {
103+
font-family: 'CustomFont';
104+
src: url('https://your-cdn.com/fonts/MyFont.woff2') format('woff2');
105+
font-weight: normal;
106+
font-style: normal;
107+
}
108+
109+
body {
110+
font-family: 'CustomFont', sans-serif;
111+
}
112+
`
113+
});
114+
```
115+
116+
</TabItem> </Tabs>
117+
118+
119+
<Tabs> <TabItem label="JavaScript" icon="seti:javascript">
120+
Example with playwright and a Base64 encoded data source:
121+
122+
```js
123+
const browser = await playwright.launch(env.MYBROWSER);
124+
const page = await browser.newPage();
125+
await page.addStyleTag({
126+
content: `
127+
@font-face {
128+
font-family: 'CustomFont';
129+
src: url('data:font/woff2;base64,<BASE64_STRING>') format('woff2');
130+
font-weight: normal;
131+
font-style: normal;
132+
}
133+
134+
body {
135+
font-family: 'CustomFont', sans-serif;
136+
}
137+
`
138+
});
139+
```
140+
141+
</TabItem> <TabItem label="TypeScript" icon="seti:typescript">
142+
Example with playwright and a Base64 encoded data source:
143+
144+
```ts
145+
const browser = await puppeteer.launch(env.MYBROWSER);
146+
const page = await browser.newPage();
147+
await page.addStyleTag({
148+
content: `
149+
@font-face {
150+
font-family: 'CustomFont';
151+
src: url('data:font/woff2;base64,<BASE64_STRING>') format('woff2');
152+
font-weight: normal;
153+
font-style: normal;
154+
}
155+
156+
body {
157+
font-family: 'CustomFont', sans-serif;
158+
}
159+
`
160+
});
161+
```
162+
163+
</TabItem> </Tabs>

0 commit comments

Comments
 (0)