| Approach | Install | Best for |
|---|---|---|
| Tailwind CSS | @pdfn/tailwind | Rapid development, utility classes |
| CSS prop | Nothing extra | Custom stylesheets, design systems |
| Inline styles | Nothing extra | Simple templates, quick prototypes |
Tailwind CSS
Install@pdfn/tailwind:
Page content with the Tailwind component:
Place
Tailwind inside Document but it can wrap one or more Page components.Custom theme
Customize your PDF theme inpdfn-templates/styles.css. This file is auto-detected and isolated from your app’s styles — your app and PDF templates never interfere with each other.
pdfn-templates/styles.css
Edge runtime (Vercel Edge, Cloudflare Workers)
Edge runtimes don’t have filesystem access, so Tailwind must be pre-compiled at build time. For Next.js:next.config.ts
vite.config.ts
CSS prop
Add custom CSS directly via thecss prop on Document. No extra packages needed.
Inline styles
Use React’sstyle prop for styling without extra dependencies:
Combining approaches
You can mix all three approaches. Styles are applied in this order (later wins):- Base pdfn styles
- Tailwind CSS classes
- Document
cssprop - Inline
styleprop
Fonts
Load custom fonts via thefonts prop on Document. Pdfn supports Google Fonts and local font files.
Google Fonts
Pass font names as strings, or configure weights and styles:| Field | Type | Default | Description |
|---|---|---|---|
family | string | — | Font family name (must match Google Fonts) |
weights | number[] | [400, 500, 600, 700] | Font weights to include |
style | "normal" | "italic" | "normal" | Font style |
Local fonts
Embed custom font files directly. The font is base64-encoded into the PDF.| Field | Type | Default | Description |
|---|---|---|---|
family | string | — | Font family name (use in CSS) |
src | string | — | Path to font file (.woff2, .woff, .ttf, .otf) |
weight | number | 400 | Font weight |
style | "normal" | "italic" | "normal" | Font style |
Local fonts require filesystem access and won’t work on edge runtimes (Vercel Edge, Cloudflare Workers). Use Google Fonts for edge compatibility.
Images
Images must be accessible when the PDF is generated. Since pdfn Cloud renders on remote servers, local filesystem paths won’t work in production.Next.js public folder
Put images in yourpublic/ folder and reference them with absolute URLs. These deploy with your app and work everywhere.
CDN-hosted images
For large assets or images shared across projects, host them on a CDN (Cloudflare R2, AWS S3, Vercel Blob).Base64 data URLs
For small images like logos or icons (under 10KB), embed them directly.Local image paths (like
./images/logo.png) work during development but fail in production. Always use absolute URLs or base64.PDF-specific CSS notes
Some CSS properties behave differently in PDFs:| Property | Behavior |
|---|---|
| Flexbox & Grid | Fully supported |
box-shadow | Works, but avoid blur > 10px (slow rendering) |
position: fixed | Behaves like absolute (no viewport in PDFs) |
vh / vw units | Relative to page size, not browser viewport |
@media print | Respected — use for PDF-specific styles |