Skip to content
Advertisement

Merge PDF with PDF-LIB

I am trying to replicate the official example for merging 2 pdf files, but instead of hardcode the name of the file, I’d like to have the user upload two files. The code works well when the filename is hardcoded (see url2) but doesn’t work when trying to retrieve the filename from the input tag. What am I doing wrong?

JavaScript

Advertisement

Answer

  1. I think the problem is in this code: I guess you would like to write: “files[0]” instead of “file[0]”.

  2. fetch method requires url (path) to resource from the web, but your uploaded file is not available under url1. You can try it by typing url1 in address bar in browser.

  3. I think that variable doc2 is not required. Probably you could write directly:

    const pdf2 = await PDFDocument.load('Patient_Card.pdf')

JavaScript

Working for me code:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement