javascript - How to get pdf title using pdf.js? -


the question is: how can name of pdf file using pdf.js? i'm running variation of pdf.js example node, , wondering if it's @ possible it. i've been searching through pdf.js's docs/source, couldn't find obvious. i'm using code, (so far) shows number of pages of each file found on given folder (in case, directory code 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 = 0; < 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 name of file in doc object attribute or that, doesn't seem case here, , couldn't find in docs. there i'm missing or doing wrong here?

i fixed :) code looks now:

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) {  //this essential change: use foreach() instead of loop files.foreach(function(file){     var data = new uint8array(fs.readfilesync(file));     pdfjs.getdocument(data)       .then(function (doc) {         var numpages = doc.numpages;         console.log('file name: ' + file + ', number of pages: ' + numpages);         console.log();       });   }); }); 

hope helps someone, , quick replies :)


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -