Docs menu · PDF fonts, images and CSS files
Guides
PDF fonts, images and CSS files
Send the files your PDF needs with the request: CSS, images, fonts and scripts. During the public preview remote file loading is off, so a render uses the files you attach.
During the public preview, remote file loading is disabled: a render cannot download anything from the internet. Send the files your page needs with the request, in assets.
Send files in assets
- Give each file a name, such as
style.cssorimages/logo.png. - Use that name in your HTML, as you would on a website:
<link rel="stylesheet" href="style.css">,<img src="images/logo.png">. - Put the files in the request under
assets, each one under its name, with the content encoded as base64.
Names are plain relative paths: write style.css, not /style.css. In the HTML, either form works. A name can contain spaces or accents, such as images/Company Logo.png or café.png. Write it in your HTML exactly as you wrote it in assets.
A complete example
This example creates a folder with a stylesheet and a logo, packages them into a request with a few lines of Python, and sends them to Stolid PDF. It uses your STOLID_API_KEY environment variable from the Quickstart.
mkdir -p invoice-demo/images && cd invoice-demo printf 'body { font-family: Inter, sans-serif; color: #1f2933; } h1 { color: #1f4e79; }' > style.css printf '<svg xmlns="http://www.w3.org/2000/svg" width="120" height="40"><rect width="120" height="40" rx="6" fill="#1f4e79"/></svg>' > images/logo.svg python3 - <<'EOF' import base64, json, pathlib def file_b64(path): return base64.b64encode(pathlib.Path(path).read_bytes()).decode("ascii") html = """ <link rel="stylesheet" href="style.css"> <img src="images/logo.svg" alt="Logo"> <h1>Invoice #1042</h1> <p>Thank you for your business.</p> """ request = { "html": html, "assets": {"style.css": file_b64("style.css"), "images/logo.svg": file_b64("images/logo.svg")}, } pathlib.Path("request.json").write_text(json.dumps(request)) EOF curl -sS -X POST "https://api.stolid.dev/v1/pdf" \ -H "Authorization: Bearer $STOLID_API_KEY" \ -H "Content-Type: application/json" \ --data-binary @request.json \ -o render.json python3 -c 'import json; r = json.load(open("render.json")); print(r.get("status"), r.get("id"), r.get("error", ""))'
Stay in invoice-demo. If the status is running, ask for the render again, as in the Quickstart, until it finishes. After succeeded, download the PDF and return to the parent folder:
curl -sS -o invoice.pdf "$(python3 -c 'import json; print(json.load(open("render.json"))["pdf_url"])')" cd ..
Open invoice-demo/invoice.pdf. To use your own files, change the file names in the Python part. With the client libraries you skip the base64 step: you pass the file contents and they do the encoding.
Fonts
You can use these fonts by name, with no upload:
| Style | Fonts |
|---|---|
| Sans-serif | Inter, Roboto, Noto Sans, Liberation Sans (looks like Arial), or simply sans-serif |
| Serif | Noto Serif, Liberation Serif (looks like Times New Roman), or serif |
| Monospace | Noto Sans Mono, Liberation Mono (looks like Courier New), or monospace |
| Chinese, Japanese, Korean | Noto Sans CJK (SC, TC, JP, KR, HK) |
| Emoji | Noto Color Emoji |
Your brand font
Send the font file (.woff2, .woff, .ttf or .otf) as an asset, like the stylesheet above, and declare it in your CSS. Make sure your font licence allows embedding.
@font-face { font-family: "Brand"; src: url("fonts/brand.woff2"); }
body { font-family: "Brand", sans-serif; }
In the example above, that means adding "fonts/brand.woff2": file_b64("fonts/brand.woff2") to assets. If the file cannot be used, the report shows FONT_FACE_FAILED (the file did not load) together with FONT_FALLBACK (which font was used instead).
Scripts
If your page needs a script, such as a pagination library, send it in assets. When a script is missing, ASSET_FAILED names the file, and whatever it would have done does not happen: page totals may show 0, for example.
Related
- Warning codes: what ASSET_FAILED, FONT_FALLBACK and the others mean.
- Page options: headers, footers and page size.
Public preview: free while we work with early users. Use sample data; there is no uptime commitment yet.