Install pdf.lib to N8N to merge multiple PDF's in one

Hi everyone,

I’m trying to use pdf-lib in an n8n Function Node, but I keep getting the error “pdf-lib not found”. I built a custom Docker image where I installed pdf-lib, but it still doesn’t seem to work.
{Cannot find module ‘pdf-lib’ [line 1], VMError}

I also tried installing it temporarily during runtime, but I still get the same error. I know there are API services for merging PDFs, but I want to run everything locally. I also looked into Strilling PDF, but unfortunately, I couldn’t get it to work properly.
Strilling Error{The service was not able to process your request [item 0]}

If anyone knows how to set up pdf-lib (or an alternative like Sterling PDF) correctly in n8n, I’d really appreciate some help.

Thanks in advance!
Nick

Information on your n8n setup

  • **n8n version: 1.76.1
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • **Running n8n via :Docker
  • **Operating system: Linux

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

I have the similar challenge with pdf-lib and error: Cannot find module ‘@pdf-lib/standard-fonts’ null

I am building on to of the starter-kit docker compose.

In docker-compose.yml I have added
volumes:
- ./node_modules/pdf-lib:/usr/local/lib/node_modules/pdf-lib

and
environment:
- NODE_FUNCTION_ALLOW_EXTERNAL=${NODE_FUNCTION_ALLOW_EXTERNAL}

And in .env I have lines:
NODE_FUNCTION_ALLOW_BUILTIN=*
NODE_FUNCTION_ALLOW_EXTERNAL=*

And I installed the pdf-lib with npm install pdf-lib

Also have Dockerfile:
FROM n8nio/n8n:latest
USER root
RUN npm install -g pdf-lib
USER node

Then running
% docker compose create && docker compose up

When trying simple Code node with
const { PDFDocument } = require(‘pdf-lib’);

But I get the error “Cannot find module ‘@pdf-lib/standard-fonts’ null”

are there somewhere docs about solving JS library issues in local docker environment?

Thanks!

1 Like