|
| 1 | +import { Tabs, TabItem } from "~/components"; |
| 2 | + |
1 | 3 | --- |
2 | 4 | pcx_content_type: reference |
3 | 5 | title: Supported fonts |
@@ -59,3 +61,100 @@ Browser Rendering includes additional font packages for non-Latin scripts and em |
59 | 61 | - Noto Color Emoji |
60 | 62 | - TLWG Thai fonts |
61 | 63 | - WenQuanYi Zen Hei (Chinese) |
| 64 | + |
| 65 | +## Using custom fonts |
| 66 | + |
| 67 | +Should you need to use an unsupported custom font, make sure it is loaded on your website, if you own it, or add the font using `addStyleTag`. |
| 68 | + |
| 69 | +<Tabs> <TabItem label="JavaScript" icon="seti:javascript"> |
| 70 | +With a CDN source: |
| 71 | + |
| 72 | +```js |
| 73 | +const browser = await puppeteer.launch(env.MYBROWSER); |
| 74 | +const page = await browser.newPage(); |
| 75 | +await page.addStyleTag({ |
| 76 | + content: ` |
| 77 | + @font-face { |
| 78 | + font-family: 'CustomFont'; |
| 79 | + src: url('https://your-cdn.com/fonts/MyFont.woff2') format('woff2'); |
| 80 | + font-weight: normal; |
| 81 | + font-style: normal; |
| 82 | + } |
| 83 | +
|
| 84 | + body { |
| 85 | + font-family: 'CustomFont', sans-serif; |
| 86 | + } |
| 87 | + ` |
| 88 | +}); |
| 89 | +``` |
| 90 | + |
| 91 | +</TabItem> <TabItem label="TypeScript" icon="seti:typescript"> |
| 92 | +With a CDN source: |
| 93 | + |
| 94 | +```ts |
| 95 | +const browser = await puppeteer.launch(env.MYBROWSER); |
| 96 | +const page = await browser.newPage(); |
| 97 | +await page.addStyleTag({ |
| 98 | + content: ` |
| 99 | + @font-face { |
| 100 | + font-family: 'CustomFont'; |
| 101 | + src: url('https://your-cdn.com/fonts/MyFont.woff2') format('woff2'); |
| 102 | + font-weight: normal; |
| 103 | + font-style: normal; |
| 104 | + } |
| 105 | +
|
| 106 | + body { |
| 107 | + font-family: 'CustomFont', sans-serif; |
| 108 | + } |
| 109 | + ` |
| 110 | +}); |
| 111 | +``` |
| 112 | + |
| 113 | +</TabItem> </Tabs> |
| 114 | + |
| 115 | + |
| 116 | +<Tabs> <TabItem label="JavaScript" icon="seti:javascript"> |
| 117 | +With a Base64 encoded data source: |
| 118 | + |
| 119 | +```js |
| 120 | +const browser = await puppeteer.launch(env.MYBROWSER); |
| 121 | +const page = await browser.newPage(); |
| 122 | +await page.addStyleTag({ |
| 123 | + content: ` |
| 124 | + @font-face { |
| 125 | + font-family: 'CustomFont'; |
| 126 | + src: url('data:font/woff2;base64,<BASE64_STRING>') format('woff2'); |
| 127 | + font-weight: normal; |
| 128 | + font-style: normal; |
| 129 | + } |
| 130 | +
|
| 131 | + body { |
| 132 | + font-family: 'CustomFont', sans-serif; |
| 133 | + } |
| 134 | + ` |
| 135 | +}); |
| 136 | +``` |
| 137 | + |
| 138 | +</TabItem> <TabItem label="TypeScript" icon="seti:typescript"> |
| 139 | +With a Base64 encoded data source: |
| 140 | + |
| 141 | +```ts |
| 142 | +const browser = await puppeteer.launch(env.MYBROWSER); |
| 143 | +const page = await browser.newPage(); |
| 144 | +await page.addStyleTag({ |
| 145 | + content: ` |
| 146 | + @font-face { |
| 147 | + font-family: 'CustomFont'; |
| 148 | + src: url('data:font/woff2;base64,<BASE64_STRING>') format('woff2'); |
| 149 | + font-weight: normal; |
| 150 | + font-style: normal; |
| 151 | + } |
| 152 | +
|
| 153 | + body { |
| 154 | + font-family: 'CustomFont', sans-serif; |
| 155 | + } |
| 156 | + ` |
| 157 | +}); |
| 158 | +``` |
| 159 | + |
| 160 | +</TabItem> </Tabs> |
0 commit comments