Closed btray77 closed 9 years ago
The way PDF-Merge is constructed is for you to give it a list of files, as in absolute path to the files. So basically all you need to do is make an array out of all the filenames in your folder, and use it in the pdfMerge constructor.
The following example should work fine:
var fs = require('fs');
var PDFMerge = require('pdf-merge');
//Get files
var pdfFiles = fs.readdirSync('./path/to/folder/with/100/pdf/files')
//Construct a new pdfMerge instance with the given files
var pdfMerge = new PDFMerge(pdfFiles)
pdfMerge.merge(function(error, result) {
});
I've never tested this module on more than 50 PDF files, so if you run into any issues let me know.
Thanks for the quick suggestion!
I'll let you know if I have any issues.
@wubzz can you complete the sample code up to where all the files inside the './path/to/folder/with/100/pdf/files'
are already generated in a specific location? It's my first time to use this and it will be a great benefit for those like me. btw, I'm a windows user. thanks
@pwong2 Not entirely sure what you mean, but I realize a mistake in the example above.
const PDFMerge = require('pdf-merge');
const path = '/path/to/folder/with/files';
const pdfFiles = fs.readdirSync(path).map((file) => [path, file].join('/'));
PDFMerge(pdfFiles)
.then((buffer) => {
console.log(buffer.toString());
});
@wubzz what if I want to generate those 50 files into a single physical file? what is the location of the generated merged pdfs?
Thanks for making this. I want to merge a folder of pdfs into a single file. Can you do an example of how you would suggest doing this as efficiently? There will be 100+ pdfs in a folder.
Thanks