wubzz / pdf-merge

Merge multiple PDF Files into a single PDF document

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Merge buffers as opposed to files?

soryy708 opened this issue · comments

Suppose I don't want to have temporary PDFs on my server. The server creates PDFs, merges them, and streams them to the client (all through buffers).
The benefit of this lib compared to the others that do the same thing is that it can return a buffer instead of creating a file on the filesystem.

Is it possible to, as opposed to giving it an array of paths to files, to give it an array of buffers to merge?

commented

Certainly possible, but the lib would in any case still need to write these buffers to disk temporarily, since the underlying lib (PDFtk) that actually does the merge requires the files to exist on disk.

Wouldn't that be slow at scale? (read/write from/to hard disk is way slower than shuffling things in RAM)

I suppose if PDFtk requires the files to exist, if given a buffer the lib would need to create a file anyway. Whether the lib does it or the user doesn't matter much.

commented

Precisely.

For what you are proposing to work PDFtk would need to allow strings (buffer -> string) to be passed into the CLI, which is something I do not think it currently supports, aside from filepath strings of course.