PDF-LIB icon

PDF-LIB

Perform operations on PDF files (get info, split)

Code PDF-LIB

AI-generated

Summary

Executes user‑supplied JavaScript code using the PDF‑LIB library on each input item.

Inputs

  • binaryPropertyName — Name of the binary property containing the PDF file to operate on; default is 'data'. Set to 'NOPDF' to start with a blank PDF.
  • pdf-code (required) — JavaScript code to run. The code receives a context with PDF‑LIB, Buffer, fs, n8n helpers, and must push result objects into the provided returnData array.

Output shape

array of items, one per input item; each item contains whatever the user code pushed into returnData (typically a json field and optionally a binary field for PDFs).

The user code can manipulate the loaded PDF document (pdfDoc) and use the provided drawCode128B helper, among others. Errors are handled according to the node's continueOnFail setting.

Examples

Example 1: Add a page number to each page of an input PDF

Set binaryPropertyName to the property holding the PDF (default 'data'). In pdf‑code, loop through pages and draw text using PDF‑LIB, then push the modified PDF as binary: returnData.push({ json: {}, binary: { pdf: { data: await pdfDoc.save(), fileName: 'numbered.pdf', mimeType: 'application/pdf' } }});.

Links

Discussion