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

I did a workaround of creating a microservice that handles the pdfs, defined it in the docker compose yml to startup with other services (based on the starter kit), and a code node that calls the microservice.

Hi, @ONLimitt
We’ve launched new custom node for working with PDF files.

Using this node, you can create a new PDF file from HTML, merge multiple PDF files or take a screenshot of a website.
All you need is just an API key for customjs.space.
You can also use our template for merging multiple PDF files.

All the bests.
Thank you.

Tried this @olaf11071107 but it couldn’t handle 5 PDF’s, do we need to batch or does that defeat the purpose?

413 - “{"Message":"Request must be smaller than 6291456 bytes for the InvokeFunction operation"}”

I had 5 PDF’s average size 400kb each

We are really sorry, @jakeThai
That’s because of the issue with payload size exceeds.
We are working with it right now.
You can still try with small PDF files like invoice or something.
Thank you for your interests.
Have a good day.

1 Like

You can use a docker container like Stirling PDF and its apis

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.