The question is: How can I get the name of the pdf file using pdf.js? I'm running a variation of a pdf.js example from node, and I was wondering if it's at all possible to get it. I've been searching through pdf.js's docs/source, but couldn't find anything obvious. I'm using this code, which (so far) shows the number of pages of each file found on a given folder (in this case, the directory this code is being run from):
var fs = require('fs');
var glob = require('glob');
global.window = global;
global.navigator = { userAgent: "node" };
global.PDFJS = {};
global.DOMParser = require('./domparsermock.js').DOMParserMock;
require('../../build/singlefile/build/pdf.combined.js');
glob("**/*.pdf", function (er, files) {
for(var i = 0; i < files.length; i++){
var data = new Uint8Array(fs.readFileSync(files[i]));
PDFJS.getDocument(data).then(function (doc) {
var numPages = doc.numPages;
console.log('Number of Pages: ' + numPages);
console.log();
}).then(function () {
console.log('# End of Document');
}, function (err) {
console.error('Error: ' + err);
});
}
});
I thought the name of the file was in the doc object as an attribute or something like that, but that doesn't seem to be the case here, and I couldn't find anything about this in the docs. Is there something I'm missing or doing wrong here?