Search code examples
javascriptnode.jspdfnode-pdfkit

pdfkit js read from file


I am working on a nodejs service where I need to read a PDF document from a file.

At a high level, here is the workflow. First time a user requests a PDF, I generate it (using pdfkitjs) and save it to the server. Then, when the user request the same document again, I need to read it from the server and send it back.

Is there a way that I can use PDFDocument from pdfkitjs to read the contents from the file and create a corresponding PDFDocument? Almost all searches come up with how to pipe the PDF to a stream, but now how to read from a stream.


Solution

  • If "the stream" is your server response then you shouldn't have to do much more than add the appropriate headers to the response first.