How get page count of pdf document using node js

sample code for How get page count of pdf document using node js

@bilbi_John

You can use GetPages API method for the purpose. Please find sample Node.js code to count the PDF page count.

const { PdfApi } = require("asposepdfcloud");

pdfApi = new PdfApi("xxxxx-xxxx-xxxx-xxxx-xxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxx");

var fs = require('fs');

const name = "02_pages.pdf";
const remoteTempFolder = "Temp";
//const localTestDataFolder = "C:\\Temp";
//const path = remoteTempFolder + "\\" + name;
//var data = fs.readFileSync(localTestDataFolder + "\\" + name);

// Upload File
//pdfApi.uploadFile(path, data).then((result) => {  
//                     console.log("Uploaded File");    
//                    }).catch(function(err) {
    // Deal with an error
//    console.log(err);
//});


// Get Page Count
pdfApi.getPages(name, null, remoteTempFolder).then((result) => {    
    console.log("Pages Count :", result.body.pages.list.length);    			    
}).catch(function(err) {
    // Deal with an error
    console.log(err);
});
1 Like