// n8n integration

File to Base64 (from URL)

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.

Where to find it

The operation lives in the CustomJS (PDF & File Toolkit) node:

  1. Add the PDF Toolkit node to your workflow
  2. Set Resource to Data
  3. Set Operation to File to Base64 (from URL)

Configuration

Node Parameters

ParameterDescriptionRequired
File URLURL of the file to download, must start with http:// or https://Yes

Example

Input:

File URL: https://example.com/logo.png

Output:

{
  "base64": "iVBORw0KGgoAAAANSUhEUgAA...",
  "dataUri": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...",
  "contentType": "image/png",
  "bytes": 34210
}

Output Fields

FieldDescription
base64The raw Base64 encoded file content
dataUriThe complete data URI including content type, ready to drop into an src attribute or a CSS url()
contentTypeThe content type reported by the server, e.g. image/png
bytesThe file size in bytes

Embedding a logo into a PDF template

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.