New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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

to
0.1.18

dev-playground/package.json

4

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

@@ -9,3 +9,3 @@ "authors": [

"description": "Client/server side PDF printing in pure JavaScript",
"main": "build/pdfmake.js",
"main": ["build/pdfmake.js", "build/vfs_fonts.js"],
"moduleType": [

@@ -12,0 +12,0 @@ "globals"

@@ -80,9 +80,6 @@ module.exports = function(grunt) {

build: {
files: {
'build/pdfmake.js': ['./src/browser-extensions/pdfMake.js']
},
options: {
require: ['./src/browser-extensions/virtual-fs.js:fs', './src/browser-extensions/pdfmake.js:pdfMake'],
require: ['./src/browser-extensions/virtual-fs.js:fs', './src/browser-extensions/pdfMake.js:pdfMake'],
browserifyOptions: {
standalone: 'pdfMake',
standalone: 'pdfMake'
}

@@ -132,3 +129,3 @@ }

grunt.registerTask('test', [ 'replace:exposeTestMethods', 'jshint', 'mochacov', 'replace:hideTestMethods' ]);
grunt.registerTask('test', [ 'replace:fixPdfKit', 'replace:exposeTestMethods', 'jshint', 'mochacov', 'replace:hideTestMethods' ]);

@@ -135,0 +132,0 @@ grunt.registerTask('fixVfsFonts', 'Adds semicolon to the end of vfs_fonts.js', function () {

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

@@ -12,19 +12,23 @@ "main": "src/printer.js",

"lodash": "~3.1.0",
"lodash-node": "~3.1.0"
"lodash-node": "~3.1.0"
},
"devDependencies": {
"grunt": "~0.4.5",
"grunt-cli": "~0.1.13",
"grunt-jsdoc": "~0.5.8",
"grunt-contrib-jshint": "~0.11.0",
"grunt-mocha-cov": "~0.2.1",
"grunt-text-replace": "~0.4.0",
"grunt-browserify": "~3.5.0",
"grunt-contrib-uglify": "~0.8.0",
"grunt-dump-dir": "~0.1.2",
"grunt-contrib-concat": "~0.5.1",
"sinon": "~1.12.2"
"expose-loader": "^0.6.0",
"gulp": "^3.8.11",
"gulp-jshint": "^1.10.0",
"gulp-rename": "^1.2.2",
"gulp-replace": "^0.5.3",
"gulp-sourcemaps": "^1.5.2",
"gulp-spawn-mocha": "^2.0.1",
"gulp-uglify": "^1.2.0",
"gulp-util": "^3.0.4",
"gulp-webpack": "^1.4.0",
"json-loader": "^0.5.1",
"pdfkit": "^0.7.1",
"sinon": "~1.12.2",
"string-replace-webpack-plugin": "0.0.1",
"webpack": "^1.8.9"
},
"scripts": {
"test": "grunt test"
"test": "gulp"
},

@@ -31,0 +35,0 @@ "repository": {

@@ -127,3 +127,3 @@ pdfmake [![Build Status](https://travis-ci.org/bpampuch/pdfmake.png?branch=master)](https://travis-ci.org/bpampuch/pdfmake) [![NPM version](https://badge.fury.io/js/pdfmake.png)](http://badge.fury.io/js/pdfmake) [![Bower version](https://badge.fury.io/bo/pdfmake.png)](http://badge.fury.io/bo/pdfmake)

anotherStyle: {
italic: true,
italics: true,
alignment: 'right'

@@ -130,0 +130,0 @@ }

@@ -23,5 +23,5 @@ /* jslint node: true */

this.endingCell = null;
this.tracker = new TraversalTracker();
this.addPage(pageSize);

@@ -129,2 +129,37 @@ }

DocumentContext.prototype.moveTo = function(x,y) {
if(x !== undefined && x !== null) {
this.x = x;
this.availableWidth = this.getCurrentPage().pageSize.width - this.x - this.pageMargins.right;
}
if(y !== undefined && y !== null){
this.y = y;
this.availableHeight = this.getCurrentPage().pageSize.height - this.y - this.pageMargins.bottom;
}
};
DocumentContext.prototype.beginDetachedBlock = function() {
this.snapshots.push({
x: this.x,
y: this.y,
availableHeight: this.availableHeight,
availableWidth: this.availableWidth,
page: this.page,
endingCell: this.endingCell,
lastColumnWidth: this.lastColumnWidth
});
};
DocumentContext.prototype.endDetachedBlock = function() {
var saved = this.snapshots.pop();
this.x = saved.x;
this.y = saved.y;
this.availableWidth = saved.availableWidth;
this.availableHeight = saved.availableHeight;
this.page = saved.page;
this.endingCell = saved.endingCell;
this.lastColumnWidth = saved.lastColumnWidth;
};
function pageOrientation(pageOrientationString, currentPageOrientation){

@@ -141,5 +176,5 @@ if(pageOrientationString === undefined) {

var getPageSize = function (currentPage, newPageOrientation) {
newPageOrientation = pageOrientation(newPageOrientation, currentPage.pageSize.orientation);
if(newPageOrientation !== currentPage.pageSize.orientation) {

@@ -158,3 +193,3 @@ return {

}
};

@@ -193,3 +228,3 @@

this.tracker.emit('pageAdded');
return page;

@@ -212,2 +247,4 @@ };

pageOrientation: pageSize.orientation,
pageInnerHeight: innerHeight,
pageInnerWidth: innerWidth,
left: this.x,

@@ -214,0 +251,0 @@ top: this.y,

@@ -0,1 +1,4 @@

/* jslint node: true */
'use strict';
var pdfKit = require('pdfkit');

@@ -14,3 +17,3 @@ var PDFImage = require('pdfkit/js/image');

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

@@ -17,0 +20,0 @@ image.embed(this.pdfDoc);

@@ -62,3 +62,7 @@ /* jslint node: true */

_.each(linearNodeList, function(node) {
var nodeInfo = _.pick(node, ['id', 'headlineLevel', 'text', 'ul', 'ol', 'table', 'image', 'qr', 'canvas', 'columns', 'style', 'pageOrientation']);
var nodeInfo = _.pick(node, [
'id', 'text', 'ul', 'ol', 'table', 'image', 'qr', 'canvas', 'columns',
'headlineLevel', 'style', 'pageBreak', 'pageOrientation',
'width', 'height'
]);
nodeInfo.startPosition = _.first(node.positions);

@@ -73,4 +77,4 @@ nodeInfo.pageNumbers = _.chain(node.positions).map('pageNumber').uniq().value();

return _.any(linearNodeList, function (node, index, followingNodeList) {
if (node.pageBreak !== 'before') {
if (node.pageBreak !== 'before' && !node.pageBreakCalculated) {
node.pageBreakCalculated = true;
var pageNumber = _.first(node.nodeInfo.pageNumbers);

@@ -151,5 +155,5 @@

var backgroundGetter = isFunction(background) ? background : function() { return background; };
var pageBackground = backgroundGetter(this.writer.context().page + 1);
if (pageBackground) {

@@ -163,17 +167,4 @@ var pageSize = this.writer.context().getCurrentPage().pageSize;

LayoutBuilder.prototype.addStaticRepeatable = function(node, x, y, width, height) {
var pages = this.writer.context().pages;
this.writer.context().page = 0;
this.writer.beginUnbreakableBlock(width, height);
this.processNode(this.docMeasure.measureDocument(node));
var repeatable = this.writer.currentBlockToRepeatable();
repeatable.xOffset = x;
repeatable.yOffset = y;
this.writer.commitUnbreakableBlock(x, y);
for(var i = 1, l = pages.length; i < l; i++) {
this.writer.context().page = i;
this.writer.addFragment(repeatable, true, true, true);
}
LayoutBuilder.prototype.addStaticRepeatable = function(headerOrFooter, sizeFunction) {
this.addDynamicRepeatable(function() { return headerOrFooter; }, sizeFunction);
};

@@ -207,3 +198,3 @@

};
var footerSizeFct = function (pageSize, pageMargins) {

@@ -217,3 +208,3 @@ return {

};
if(isFunction(header)) {

@@ -228,3 +219,3 @@ this.addDynamicRepeatable(header, headerSizeFct);

} else if(footer) {
this.addStaticRepeatable(footer, headerSizeFct);
this.addStaticRepeatable(footer, footerSizeFct);
}

@@ -287,5 +278,17 @@ };

node.positions = [];
_.each(node.canvas, function(vector){
var x = vector.x, y = vector.y;
vector.resetXY = function(){
vector.x = x;
vector.y = y;
};
});
node.resetXY = function(){
node.x = x;
node.y = y;
_.each(node.canvas, function(vector){
vector.resetXY();
});
};

@@ -301,2 +304,8 @@ }

applyMargins(function() {
var absPosition = node.absolutePosition;
if(absPosition){
self.writer.context().beginDetachedBlock();
self.writer.context().moveTo(absPosition.x || 0, absPosition.y || 0);
}
if (node.stack) {

@@ -323,2 +332,6 @@ self.processVerticalContainer(node);

}
if(absPosition){
self.writer.context().endDetachedBlock();
}
});

@@ -572,3 +585,2 @@

module.exports = LayoutBuilder;

@@ -5,2 +5,4 @@ /* jslint node: true */

var _ = require('lodash');
var FontProvider = require('./fontProvider');
var LayoutBuilder = require('./layoutBuilder');

@@ -12,2 +14,3 @@ var PdfKit = require('pdfkit');

var textDecorator = require('./textDecorator');
var FontProvider = require('./fontProvider');

@@ -224,4 +227,2 @@ ////////////////////////////////////////

setFontRefs(fontProvider, pdfKitDoc);
var page = pages[i];

@@ -243,20 +244,7 @@ for(var ii = 0, il = page.items.length; ii < il; ii++) {

if(page.watermark){
renderWatermark(page, pdfKitDoc, fontProvider);
}
renderWatermark(page, pdfKitDoc);
}
}
function setFontRefs(fontProvider, pdfKitDoc) {
for(var fontName in fontProvider.cache) {
var desc = fontProvider.cache[fontName];
for (var fontType in desc) {
var font = desc[fontType];
var _ref, _base, _name;
if (!(_ref = (_base = pdfKitDoc.page.fonts)[_name = font.id])) {
_base[_name] = font.ref();
}
}
}
fontProvider.setFontRefsToPdfDoc();
}
}

@@ -269,3 +257,2 @@

var ascenderHeight = line.getAscenderHeight();
var lineHeight = line.getHeight();

@@ -283,9 +270,10 @@ textDecorator.drawBackground(line, x, y, pdfKitDoc);

var encoded = inline.font.encode(inline.text);
pdfKitDoc.addContent('BT');
var a = (inline.font.ascender / 1000 * inline.fontSize);
pdfKitDoc.addContent('' + (x + inline.x) + ' ' + (pdfKitDoc.page.height - y - ascenderHeight) + ' Td');
pdfKitDoc.addContent('/' + inline.font.id + ' ' + inline.fontSize + ' Tf');
pdfKitDoc.addContent('/' + encoded.fontId + ' ' + inline.fontSize + ' Tf');
pdfKitDoc.addContent('<' + encode(inline.font, inline.text) + '> Tj');
pdfKitDoc.addContent('<' + encoded.encodedText + '> Tj');

@@ -300,3 +288,3 @@ pdfKitDoc.addContent('ET');

function renderWatermark(page, pdfKitDoc, fontProvider){
function renderWatermark(page, pdfKitDoc){
var watermark = page.watermark;

@@ -313,6 +301,7 @@

var encoded = watermark.font.encode(watermark.text);
pdfKitDoc.addContent('BT');
pdfKitDoc.addContent('' + (pdfKitDoc.page.width/2 - watermark.size.size.width/2) + ' ' + (pdfKitDoc.page.height/2 - watermark.size.size.height/4) + ' Td');
pdfKitDoc.addContent('/' + watermark.font.id + ' ' + watermark.size.fontSize + ' Tf');
pdfKitDoc.addContent('<' + encode(watermark.font, watermark.text) + '> Tj');
pdfKitDoc.addContent('/' + encoded.fontId + ' ' + watermark.size.fontSize + ' Tf');
pdfKitDoc.addContent('<' + encoded.encodedText + '> Tj');
pdfKitDoc.addContent('ET');

@@ -322,18 +311,2 @@ pdfKitDoc.restore();

function encode(font, text) {
font.use(text);
text = font.encode(text);
text = ((function() {
var _results = [];
for (var i = 0, _ref2 = text.length; 0 <= _ref2 ? i < _ref2 : i > _ref2; 0 <= _ref2 ? i++ : i--) {
_results.push(text.charCodeAt(i).toString(16));
}
return _results;
})()).join('');
return text;
}
function renderVector(vector, pdfDoc) {

@@ -400,41 +373,2 @@ //TODO: pdf optimization (there's no need to write all properties everytime)

function FontProvider(fontDescriptors, pdfDoc) {
this.fonts = {};
this.pdfDoc = pdfDoc;
this.cache = {};
for(var font in fontDescriptors) {
if (fontDescriptors.hasOwnProperty(font)) {
var fontDef = fontDescriptors[font];
this.fonts[font] = {
normal: fontDef.normal,
bold: fontDef.bold,
italics: fontDef.italics,
bolditalics: fontDef.bolditalics
};
}
}
}
FontProvider.prototype.provideFont = function(familyName, bold, italics) {
if (!this.fonts[familyName]) return this.pdfDoc._font;
var type = 'normal';
if (bold && italics) type = 'bolditalics';
else if (bold) type = 'bold';
else if (italics) type = 'italics';
if (!this.cache[familyName]) this.cache[familyName] = {};
var cached = this.cache[familyName] && this.cache[familyName][type];
if (cached) return cached;
var fontCache = (this.cache[familyName] = this.cache[familyName] || {});
fontCache[type] = this.pdfDoc.font(this.fonts[familyName][type], familyName + ' (' + type + ')')._font;
return fontCache[type];
};
module.exports = PdfPrinter;

@@ -441,0 +375,0 @@

@@ -0,1 +1,4 @@

/* jslint node: true */
'use strict';
var ColumnCalculator = require('./columnCalculator');

@@ -68,5 +71,5 @@

var offset = self.rowPaddingTop + (!self.headerRows ? self.topLineWidth : 0);
writer.context().moveDown(offset);
writer.context().moveDown(offset);
};
};

@@ -79,3 +82,3 @@

this.rowPaddingBottom = this.layout.paddingBottom(rowIndex, this.tableNode);
this.rowCallback = this.onRowBreak(rowIndex, writer);

@@ -136,3 +139,3 @@ writer.tracker.startTracking('pageChanged', this.rowCallback );

var width = this.layout.vLineWidth(vLineIndex, this.tableNode);
if (width === 0) return;
if (width === 0) return;
writer.addVector({

@@ -194,2 +197,7 @@ type: 'line',

var y2 = ys[yi].y1;
if(willBreak) {
y2 = y2 + this.rowPaddingBottom;
}
if (writer.context().page != ys[yi].page) {

@@ -225,6 +233,6 @@ writer.context().page = ys[yi].page;

if (willBreak) {
if (willBreak && this.layout.hLineWhenBroken !== false) {
this.drawHorizontalLine(rowIndex + 1, writer, y2);
}
if(rowBreakWithoutHeader) {
if(rowBreakWithoutHeader && this.layout.hLineWhenBroken !== false) {
this.drawHorizontalLine(rowIndex, writer, y1);

@@ -244,3 +252,3 @@ }

if (row[i].colSpan && row[i].colSpan > 1) {
for(var j = 1; j < row[i].colSpan; j++) {
for(var j = 1; j < row[i].rowSpan; j++) {
this.tableNode.table.body[rowIndex + j][i]._colSpan = row[i].colSpan;

@@ -263,3 +271,3 @@ }

if(this.dontBreakRows) {
writer.tracker.auto('pageChanged',
writer.tracker.auto('pageChanged',
function() {

@@ -270,2 +278,3 @@ self.drawHorizontalLine(rowIndex, writer);

writer.commitUnbreakableBlock();
self.drawHorizontalLine(rowIndex, writer);
}

@@ -272,0 +281,0 @@ );