How to get the page number in a friendly way
MaXiaoCui11 opened this issue · 4 comments
MaXiaoCui11 commented
Fdawgs commented
Hi @MaXiaoCui11, that sounds like a great idea! I will investigate how easy this is to do.
sainf commented
A json flag it would be nice!
My approach :
const camelCase = require('camelcase')
const { Poppler } = require('node-poppler')
/**
* Converts node-poppler pdfInfo to an object
*
* @param {string} pathTo the full path
* @returns object with pdf information
*/
const pdfInfo = async pathTo => {
const poppler = new Poppler('/usr/bin')
const info = {}
const ret = await poppler.pdfInfo(pathTo)
ret.split('\n').map(r => r.split(': ')).forEach(r => {
if (r.length > 1) info[camelCase(r[0])] = r[1].trim()
})
return info
}
module.exports = { pdfInfo }
Fdawgs commented
@MaXiaoCui11 see #268, shamelessly stole @sainf's solution.
@sainf are you happy for me to credit you in an in-line comment, and in the changelog?
sainf commented
Happy to be part on an solution! Thanks for the comment!