Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
} else if (entry.image && entry.image.filename) {
if (!isSectionExists(sectionName)) {
addError({message: 'WARNING: Image could not be added. Section "' + sectionName + '" not found on Page ' + contentPageIndex + '.'});
return;
}
if (!filestream.existsSync(entry.image.filename) || !filestream.statSync(entry.image.filename).isFile()) {
addError({message: 'ERROR: Image "' + entry.image.filename + '" not found.'});
return;
}
var sectionDimension = getSectionDimension(sectionName),
options = entry.image.options || {};
var imgData = PDFImage.open(entry.image.filename),
imgHeight = options.height || imgData.height,
reqPageBreak = (sectionInfo.topIndex + imgHeight > sectionDimension.height),
imageTop = reqPageBreak ? sectionDimension.top || 0 : null;
if (!sectionInfo.topIndex && !imageTop) {
imageTop = sectionDimension.top;
}
// New Page if picture to big
if (reqPageBreak) {
setPage(currentPDFDocument, ++contentPageIndex);
sectionInfo.topIndex = 0; // New Page, reset Line
sectionInfo.pageIndex++;
}
currentPDFDocument.image(entry.image.filename, sectionDimension.left || 0, imageTop, {