Pra*_*ash 3 javascript pdf-generation node.js angularjs
如何使用width和height的pdf页面nodejs?
是否可以采用文件类型?
这是我的代码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)) {
//...
}
}
}
Run Code Online (Sandbox Code Playgroud)
有许多提供此功能的软件包,例如卡尺和剪刀,但我发现pdf2json很简单,不需要其他模块。这是使用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`)
});
Run Code Online (Sandbox Code Playgroud)