How to use the pdfkit/js/image.open function in pdfkit

To help you get started, we’ve selected a few pdfkit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github litixsoft / lx-pdf / lib / lx-pdf.js View on Github external
}
                    } 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, {

pdfkit

A PDF generation library for Node.js

MIT
Latest version published 5 days ago

Package Health Score

90 / 100
Full package analysis