nbesli/pdf-merger-js

The "save" method can't parse an output file name

Closed this issue · 1 comments

Enviroment:
ubuntu 19.10
node 10.22.1 (same with 14.12.0)
pdf-merger-js 3.0.5
pdfjs 2.3.9

My code snippet:

const PDFMerger = require('pdf-merger-js');
var merger = new PDFMerger();
 
(async () => {
  try {
    merger.add(__dirname + '/one.pdf');
    merger.add(__dirname + '/two.pdf');

    await merger.save(__dirname + '/merged.pdf');
    console.log("done!");

  } catch (error) {
    console.log("error:");
    console.log(error);
    console.log("__dirname:");
    console.log(__dirname);
  }
})();

Result:

Error: Name must start with a leading slash, found: %
    at Function.parse (/home/tester/Desktop/pdff/node_modules/pdfjs/lib/object/name.js:56:13)
    at Function.parse (/home/tester/Desktop/pdff/node_modules/pdfjs/lib/object/dictionary.js:71:27)
    at Object.exports.parse (/home/tester/Desktop/pdff/node_modules/pdfjs/lib/object/value.js:20:30)
    at Function.parseInner (/home/tester/Desktop/pdff/node_modules/pdfjs/lib/object/object.js:80:28)
    at Function.parse (/home/tester/Desktop/pdff/node_modules/pdfjs/lib/object/object.js:68:27)
    at parseObject (/home/tester/Desktop/pdff/node_modules/pdfjs/lib/object/reference.js:128:22)
    at PDFReference.get [as object] (/home/tester/Desktop/pdff/node_modules/pdfjs/lib/object/reference.js:15:17)
    at ExternalDocument._countPagesRecursively (/home/tester/Desktop/pdff/node_modules/pdfjs/lib/external.js:31:24)
    at new ExternalDocument (/home/tester/Desktop/pdff/node_modules/pdfjs/lib/external.js:26:27)
    at PDFMerger._addEntireDocument (/home/tester/Desktop/pdff/node_modules/pdf-merger-js/index.js:29:15)
__dirname:
/home/tester/Desktop/pdff

Expectation: merged files

I can not reproduce this problem with your code!
Maybe check if the pdf files really exists at this location:

const PDFMerger = require('pdf-merger-js');
var merger = new PDFMerger();
 
(async () => {
	var input1 = __dirname + '/one.pdf';
	var input2 = __dirname + '/two.pdf';
	var output = __dirname + '/merged.pdf';

	console.log("__dirname: ", __dirname);
	console.log("input1: ", input1);
	console.log("input2: ", input2);
	console.log("output: ", output);

  try {
    merger.add(input1);
    merger.add(input2);

    await merger.save(output);
    console.log("done!");

  } catch (error) {
    console.error(error);
  }
})();