Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pdfmake

Package Overview
Dependencies
Maintainers
1
Versions
103
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pdfmake - npm Package Compare versions

Comparing version 0.1.7 to 0.1.8

2

bower.json
{
"name": "pdfmake",
"version": "0.1.7",
"version": "0.1.8",
"homepage": "https://bpampuch.github.io/pdfmake",

@@ -5,0 +5,0 @@ "authors": [

{
"name": "pdfmake",
"version": "0.1.7",
"version": "0.1.8",
"description": "Client/server side PDF printing in pure JavaScript",

@@ -5,0 +5,0 @@ "main": "src/printer.js",

@@ -13,3 +13,3 @@ /* jslint node: true */

*/
function DocMeasure(fontProvider, styleDictionary, defaultStyle, imageMeasure, tableLayouts) {
function DocMeasure(fontProvider, styleDictionary, defaultStyle, imageMeasure, tableLayouts, images) {
this.textTools = new TextTools(fontProvider);

@@ -19,2 +19,4 @@ this.styleStack = new StyleContextStack(styleDictionary, defaultStyle);

this.tableLayouts = tableLayouts;
this.images = images;
this.autoImageIndex = 1;
}

@@ -108,3 +110,15 @@

DocMeasure.prototype.convertIfBase64Image = function(node) {
if (/^data:image\/(jpeg|jpg|png);base64,/.test(node.image)) {
var label = '$$pdfmake$$' + this.autoImageIndex++;
this.images[label] = node.image;
node.image = label;
}
};
DocMeasure.prototype.measureImage = function(node) {
if (this.images) {
this.convertIfBase64Image(node);
}
var imageSize = this.imageMeasure.measureImage(node.image);

@@ -111,0 +125,0 @@

var pdfKit = require('pdfmake-pdfkit');
function ImageMeasure(pdfDoc) {
function ImageMeasure(pdfDoc, imageDictionary) {
this.pdfDoc = pdfDoc;
this.imageDictionary = imageDictionary || {};
}

@@ -9,6 +10,7 @@

var image, label;
var that = this;
if (!this.pdfDoc._imageRegistry[src]) {
label = "I" + (++this.pdfDoc._imageCount);
image = pdfKit.PDFImage.open(src, label);
image = pdfKit.PDFImage.open(realImageSrc(src), label);
image.embed(this.pdfDoc);

@@ -21,4 +23,17 @@ this.pdfDoc._imageRegistry[src] = image;

return { width: image.width, height: image.height };
function realImageSrc(src) {
var img = that.imageDictionary[src];
if (!img) return src;
var index = img.indexOf('base64,');
if (index < 0) {
throw 'invalid image format, images dictionary should contain dataURL entries';
}
return new Buffer(img.substring(index + 7), 'base64');
}
};
module.exports = ImageMeasure;

@@ -45,4 +45,4 @@ /* jslint node: true */

*/
LayoutBuilder.prototype.layoutDocument = function (docStructure, fontProvider, styleDictionary, defaultStyle, header, footer) {
this.docMeasure = new DocMeasure(fontProvider, styleDictionary, defaultStyle, this.imageMeasure, this.tableLayouts);
LayoutBuilder.prototype.layoutDocument = function (docStructure, fontProvider, styleDictionary, defaultStyle, header, footer, images) {
this.docMeasure = new DocMeasure(fontProvider, styleDictionary, defaultStyle, this.imageMeasure, this.tableLayouts, images);

@@ -49,0 +49,0 @@ docStructure = this.docMeasure.measureDocument(docStructure);

@@ -86,6 +86,8 @@ /* jslint node: true */

docDefinition.images = docDefinition.images || {};
var builder = new LayoutBuilder(
pageSize,
fixPageMargins(docDefinition.pageMargins || 40),
new ImageMeasure(this.pdfKitDoc));
new ImageMeasure(this.pdfKitDoc, docDefinition.images));

@@ -97,3 +99,3 @@ registerDefaultTableLayouts(builder);

var pages = builder.layoutDocument(docDefinition.content, this.fontProvider, docDefinition.styles || {}, docDefinition.defaultStyle || { fontSize: 12, font: 'Roboto' }, docDefinition.header, docDefinition.footer);
var pages = builder.layoutDocument(docDefinition.content, this.fontProvider, docDefinition.styles || {}, docDefinition.defaultStyle || { fontSize: 12, font: 'Roboto' }, docDefinition.header, docDefinition.footer, docDefinition.images);

@@ -100,0 +102,0 @@ renderPages(pages, this.fontProvider, this.pdfKitDoc);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc