How to take the width
and height
of the pdf
page using nodejs
?
Is it possible to take the file type also?
Here My code for angularjs
:
$scope.demofun = function () {
var allowedFormats = ['jpeg', 'jpg', 'png', 'pdf'];
var unsupportedSizes = false;
if ($scope.file1[0].size < (5 * 1024 * 1024)) {
//Here I will check the file size and restrict the file if the size is not satisfy my condition.
//And I need to allow only A4 size pdf when uploading for that I want to get the dimension of pdf document
//but I don't able to get the dimension of pdf for that I write the code like this but it will wont works:
if (($scope.file1[0].width >= 21 && $scope.file1[0].width <= 22) && ($scope.file1.height >= 29.7 && $scope.file1.height <= 30.7)) {
//...
}
}
}
How to take the width
and height
of the pdf
page using nodejs
?
Is it possible to take the file type also?
Here My code for angularjs
:
$scope.demofun = function () {
var allowedFormats = ['jpeg', 'jpg', 'png', 'pdf'];
var unsupportedSizes = false;
if ($scope.file1[0].size < (5 * 1024 * 1024)) {
//Here I will check the file size and restrict the file if the size is not satisfy my condition.
//And I need to allow only A4 size pdf when uploading for that I want to get the dimension of pdf document
//but I don't able to get the dimension of pdf for that I write the code like this but it will wont works:
if (($scope.file1[0].width >= 21 && $scope.file1[0].width <= 22) && ($scope.file1.height >= 29.7 && $scope.file1.height <= 30.7)) {
//...
}
}
}
Share
Improve this question
edited Mar 20, 2019 at 7:26
Multihunter
5,9682 gold badges28 silver badges39 bronze badges
asked Feb 15, 2018 at 13:22
PrakashPrakash
3365 silver badges18 bronze badges
4
- please add what you have tried so far – Dathan Commented Feb 15, 2018 at 13:36
- I didn't tried yet because I thought in angularjs it is possible to take the dimension but now only I realize it's not possible thats why I am tried with node.js is it possible? – Prakash Commented Feb 15, 2018 at 13:45
- can you post your code ? – Dipak Commented Feb 15, 2018 at 15:22
- I posted my code above sir,please check & give me the solution.But that code is for angularjs-@Dipak chavda – Prakash Commented Feb 16, 2018 at 6:17
2 Answers
Reset to default 8There are many packages which provides this like calipers and scissors, But i found pdf2json is simple and doesn't require on other modules. Here's how you can get width and height using pdf2json
PDFParser = require("pdf2json");
let pdfParser = new PDFParser();
pdfParser.loadPDF("./your_file_path"); // ex: ./abc.pdf
pdfParser.on("pdfParser_dataReady", pdfData => {
width = pdfData.formImage.Width / 4.5; // pdf width
height = pdfData.formImage.Pages[0].Height / 4.5; // page height
console.log(`Height : ${height} in inch`)
console.log(`Width : ${width} in inch`)
});
Please look at this, I am sure you will find solution to your problem.
https://www.npmjs./package/pdf2json#output-format-reference
This npm package will return you all the required details.