// n8n integration
This operation is available on both n8n Cloud and self-hosted n8n and requires the CustomJS community package. It ships with the next release of the @custom-js/n8n-nodes-pdf-toolkit-v2 package, available from version 0.12.0. See Installation.
The File to Base64 operation downloads a file from a URL and returns it as a Base64 string and a ready-to-use data URI.
The typical use case: embed logos, images, or fonts as a data URI directly into the HTML template of the HTML to PDF node. The PDF renderer then needs no external requests, your assets always load, and the generated PDF looks the same every time. The same trick works with the HTML to PDF API.
Files are capped at 8 MB. Larger files return an error instead of a truncated result.
The operation lives in the CustomJS (PDF & File Toolkit) node:
DataFile to Base64 (from URL)| Parameter | Description | Required |
|---|---|---|
| File URL | URL of the file to download, must start with http:// or https:// | Yes |
Input:
File URL: https://example.com/logo.png
Output:
{
"base64": "iVBORw0KGgoAAAANSUhEUgAA...",
"dataUri": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...",
"contentType": "image/png",
"bytes": 34210
}
| Field | Description |
|---|---|
| base64 | The raw Base64 encoded file content |
| dataUri | The complete data URI including content type, ready to drop into an src attribute or a CSS url() |
| contentType | The content type reported by the server, e.g. image/png |
| bytes | The file size in bytes |
Connect this operation to the HTML to PDF node and reference the data URI in your template:
<img src="{{ $json.result.dataUri }}" alt="Company logo" style="height: 48px">
The logo is now part of the HTML itself, so the PDF renders correctly even if the original URL is slow, protected, or temporarily offline.