pdfmake 0.1.67 → 0.1.71

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,74 +1,74 @@
1
- {
2
- "name": "pdfmake",
3
- "version": "0.1.67",
4
- "description": "Client/server side PDF printing in pure JavaScript",
5
- "main": "src/printer.js",
6
- "browser": "build/pdfmake.js",
7
- "directories": {
8
- "test": "tests"
9
- },
10
- "dependencies": {
11
- "iconv-lite": "^0.6.0",
12
- "linebreak": "^1.0.2",
13
- "pdfkit": "^0.11.0",
14
- "svg-to-pdfkit": "^0.1.8",
15
- "xmldoc": "^1.1.2"
16
- },
17
- "devDependencies": {
18
- "@babel/core": "^7.10.3",
19
- "@babel/plugin-transform-modules-commonjs": "^7.10.1",
20
- "@babel/preset-env": "^7.10.3",
21
- "babel-loader": "^8.1.0",
22
- "brfs": "^2.0.2",
23
- "core-js": "^3.6.5",
24
- "eslint-plugin-jsdoc": "^27.1.2",
25
- "expose-loader": "^1.0.0",
26
- "fancy-log": "^1.3.3",
27
- "file-saver": "^2.0.2",
28
- "gulp": "^4.0.2",
29
- "gulp-each": "^0.5.0",
30
- "gulp-eslint": "^6.0.0",
31
- "gulp-file-contents-to-json": "^0.2.2",
32
- "gulp-spawn-mocha": "^6.0.0",
33
- "mocha": "^7.2.0",
34
- "rewire": "^5.0.0",
35
- "sinon": "^9.0.2",
36
- "string-replace-webpack-plugin": "^0.1.3",
37
- "transform-loader": "^0.2.4",
38
- "uglifyjs-webpack-plugin": "^2.2.0",
39
- "webpack": "^4.43.0"
40
- },
41
- "engines": {
42
- "node": ">=8"
43
- },
44
- "scripts": {
45
- "build": "gulp build",
46
- "test": "gulp",
47
- "playground": "node dev-playground/server.js"
48
- },
49
- "repository": {
50
- "type": "git",
51
- "url": "git://github.com/bpampuch/pdfmake.git"
52
- },
53
- "keywords": [
54
- "pdf",
55
- "javascript",
56
- "printing",
57
- "layout"
58
- ],
59
- "author": "Bartek Pampuch <bartosz.pampuch@gmail.com>",
60
- "license": "MIT",
61
- "bugs": {
62
- "url": "https://github.com/bpampuch/pdfmake/issues"
63
- },
64
- "homepage": "http://pdfmake.org",
65
- "config": {
66
- "blanket": {
67
- "pattern": "src",
68
- "data-cover-never": [
69
- "node_modules",
70
- "tests"
71
- ]
72
- }
73
- }
74
- }
1
+ {
2
+ "name": "pdfmake",
3
+ "version": "0.1.71",
4
+ "description": "Client/server side PDF printing in pure JavaScript",
5
+ "main": "src/printer.js",
6
+ "browser": "build/pdfmake.js",
7
+ "directories": {
8
+ "test": "tests"
9
+ },
10
+ "dependencies": {
11
+ "iconv-lite": "^0.6.2",
12
+ "linebreak": "^1.0.2",
13
+ "pdfkit": "^0.12.0",
14
+ "svg-to-pdfkit": "^0.1.8",
15
+ "xmldoc": "^1.1.2"
16
+ },
17
+ "devDependencies": {
18
+ "@babel/core": "^7.12.10",
19
+ "@babel/plugin-transform-modules-commonjs": "^7.12.1",
20
+ "@babel/preset-env": "^7.12.11",
21
+ "babel-loader": "^8.2.2",
22
+ "brfs": "^2.0.2",
23
+ "core-js": "^3.8.1",
24
+ "eslint-plugin-jsdoc": "^30.7.9",
25
+ "expose-loader": "^1.0.3",
26
+ "fancy-log": "^1.3.3",
27
+ "file-saver": "^2.0.5",
28
+ "gulp": "^4.0.2",
29
+ "gulp-each": "^0.5.0",
30
+ "gulp-eslint": "^6.0.0",
31
+ "gulp-file-contents-to-json": "^0.2.2",
32
+ "gulp-spawn-mocha": "^6.0.0",
33
+ "mocha": "7.2.0",
34
+ "rewire": "^5.0.0",
35
+ "sinon": "^9.2.2",
36
+ "string-replace-webpack-plugin": "^0.1.3",
37
+ "terser-webpack-plugin": "2.3.8",
38
+ "transform-loader": "^0.2.4",
39
+ "webpack": "^4.44.2"
40
+ },
41
+ "engines": {
42
+ "node": ">=8"
43
+ },
44
+ "scripts": {
45
+ "build": "gulp build",
46
+ "test": "gulp",
47
+ "playground": "node dev-playground/server.js"
48
+ },
49
+ "repository": {
50
+ "type": "git",
51
+ "url": "git://github.com/bpampuch/pdfmake.git"
52
+ },
53
+ "keywords": [
54
+ "pdf",
55
+ "javascript",
56
+ "printing",
57
+ "layout"
58
+ ],
59
+ "author": "Bartek Pampuch <bartosz.pampuch@gmail.com>",
60
+ "license": "MIT",
61
+ "bugs": {
62
+ "url": "https://github.com/bpampuch/pdfmake/issues"
63
+ },
64
+ "homepage": "http://pdfmake.org",
65
+ "config": {
66
+ "blanket": {
67
+ "pattern": "src",
68
+ "data-cover-never": [
69
+ "node_modules",
70
+ "tests"
71
+ ]
72
+ }
73
+ }
74
+ }
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  // Internet Explorer polyfills
4
- if (window && !window.Promise) {
4
+ if (typeof window !== 'undefined' && !window.Promise) {
5
5
  require('core-js/features/promise');
6
6
  }
7
7
  require('core-js/es/object/values');
@@ -81,11 +81,7 @@ LayoutBuilder.prototype.layoutDocument = function (docStructure, fontProvider, s
81
81
  }
82
82
  });
83
83
  nodeInfo.startPosition = node.positions[0];
84
- nodeInfo.pageNumbers = node.positions.map(function (node) {
85
- return node.pageNumber;
86
- }).filter(function (element, position, array) {
87
- return array.indexOf(element) === position;
88
- });
84
+ nodeInfo.pageNumbers = Array.from(new Set(node.positions.map(function (node) { return node.pageNumber; })));
89
85
  nodeInfo.pages = pages.length;
90
86
  nodeInfo.stack = isArray(node.stack);
91
87
 
@@ -100,17 +96,21 @@ LayoutBuilder.prototype.layoutDocument = function (docStructure, fontProvider, s
100
96
  var followingNodesOnPage = [];
101
97
  var nodesOnNextPage = [];
102
98
  var previousNodesOnPage = [];
103
- for (var ii = index + 1, l = linearNodeList.length; ii < l; ii++) {
104
- if (linearNodeList[ii].nodeInfo.pageNumbers.indexOf(pageNumber) > -1) {
105
- followingNodesOnPage.push(linearNodeList[ii].nodeInfo);
106
- }
107
- if (linearNodeList[ii].nodeInfo.pageNumbers.indexOf(pageNumber + 1) > -1) {
108
- nodesOnNextPage.push(linearNodeList[ii].nodeInfo);
99
+ if (pageBreakBeforeFct.length > 1) {
100
+ for (var ii = index + 1, l = linearNodeList.length; ii < l; ii++) {
101
+ if (linearNodeList[ii].nodeInfo.pageNumbers.indexOf(pageNumber) > -1) {
102
+ followingNodesOnPage.push(linearNodeList[ii].nodeInfo);
103
+ }
104
+ if (pageBreakBeforeFct.length > 2 && linearNodeList[ii].nodeInfo.pageNumbers.indexOf(pageNumber + 1) > -1) {
105
+ nodesOnNextPage.push(linearNodeList[ii].nodeInfo);
106
+ }
109
107
  }
110
108
  }
111
- for (var ii = 0; ii < index; ii++) {
112
- if (linearNodeList[ii].nodeInfo.pageNumbers.indexOf(pageNumber) > -1) {
113
- previousNodesOnPage.push(linearNodeList[ii].nodeInfo);
109
+ if (pageBreakBeforeFct.length > 3) {
110
+ for (var ii = 0; ii < index; ii++) {
111
+ if (linearNodeList[ii].nodeInfo.pageNumbers.indexOf(pageNumber) > -1) {
112
+ previousNodesOnPage.push(linearNodeList[ii].nodeInfo);
113
+ }
114
114
  }
115
115
  }
116
116
  if (pageBreakBeforeFct(node.nodeInfo, followingNodesOnPage, nodesOnNextPage, previousNodesOnPage)) {
package/src/printer.js CHANGED
@@ -207,6 +207,8 @@ function calculatePageHeight(pages, margins) {
207
207
  return item.item.getHeight();
208
208
  } else if (item.item._height) {
209
209
  return item.item._height;
210
+ } else if (item.type === 'vector') {
211
+ return item.item.y1 > item.item.y2 ? item.item.y1 : item.item.y2;
210
212
  } else {
211
213
  // TODO: add support for next item types
212
214
  return 0;
@@ -214,7 +216,7 @@ function calculatePageHeight(pages, margins) {
214
216
  }
215
217
 
216
218
  function getBottomPosition(item) {
217
- var top = item.item.y;
219
+ var top = item.item.y || 0;
218
220
  var height = getItemHeight(item);
219
221
  return top + height;
220
222
  }
@@ -406,6 +408,25 @@ function renderPages(pages, fontProvider, pdfKitDoc, progressCallback) {
406
408
  }
407
409
  }
408
410
 
411
+ /**
412
+ * Shift the "y" height of the text baseline up or down (superscript or subscript,
413
+ * respectively). The exact shift can / should be changed according to standard
414
+ * conventions.
415
+ *
416
+ * @param {number} y
417
+ * @param {any} inline
418
+ */
419
+ function offsetText(y, inline) {
420
+ var newY = y;
421
+ if (inline.sup) {
422
+ newY -= inline.fontSize * 0.75;
423
+ }
424
+ if (inline.sub) {
425
+ newY += inline.fontSize * 0.35;
426
+ }
427
+ return newY;
428
+ }
429
+
409
430
  function renderLine(line, x, y, pdfKitDoc) {
410
431
  function preparePageNodeRefLine(_pageNodeRef, inline) {
411
432
  var newWidth;
@@ -481,18 +502,20 @@ function renderLine(line, x, y, pdfKitDoc) {
481
502
 
482
503
  pdfKitDoc._font = inline.font;
483
504
  pdfKitDoc.fontSize(inline.fontSize);
484
- pdfKitDoc.text(inline.text, x + inline.x, y + shiftToBaseline, options);
505
+
506
+ var shiftedY = offsetText(y + shiftToBaseline, inline);
507
+ pdfKitDoc.text(inline.text, x + inline.x, shiftedY, options);
485
508
 
486
509
  if (inline.linkToPage) {
487
510
  var _ref = pdfKitDoc.ref({ Type: 'Action', S: 'GoTo', D: [inline.linkToPage, 0, 0] }).end();
488
- pdfKitDoc.annotate(x + inline.x, y + shiftToBaseline, inline.width, inline.height, {
511
+ pdfKitDoc.annotate(x + inline.x, shiftedY, inline.width, inline.height, {
489
512
  Subtype: 'Link',
490
513
  Dest: [inline.linkToPage - 1, 'XYZ', null, null, null]
491
514
  });
492
515
  }
493
516
 
494
517
  }
495
-
518
+ // Decorations won't draw correctly for superscript
496
519
  textDecorator.drawDecorations(line, x, y, pdfKitDoc);
497
520
  }
498
521
 
@@ -607,7 +630,18 @@ function renderVector(vector, pdfKitDoc) {
607
630
  function renderImage(image, x, y, pdfKitDoc) {
608
631
  var opacity = isNumber(image.opacity) ? image.opacity : 1;
609
632
  pdfKitDoc.opacity(opacity);
610
- pdfKitDoc.image(image.image, image.x, image.y, { width: image._width, height: image._height });
633
+ if (image.cover) {
634
+ var align = image.cover.align || 'center';
635
+ var valign = image.cover.valign || 'center';
636
+ var width = image.cover.width ? image.cover.width : image.width;
637
+ var height = image.cover.height ? image.cover.height : image.height;
638
+ pdfKitDoc.save();
639
+ pdfKitDoc.rect(image.x, image.y, width, height).clip();
640
+ pdfKitDoc.image(image.image, image.x, image.y, { cover: [width, height], align: align, valign: valign });
641
+ pdfKitDoc.restore();
642
+ } else {
643
+ pdfKitDoc.image(image.image, image.x, image.y, { width: image._width, height: image._height });
644
+ }
611
645
  if (image.link) {
612
646
  pdfKitDoc.link(image.x, image.y, image._width, image._height, image.link);
613
647
  }
@@ -103,7 +103,9 @@ StyleContextStack.prototype.autopush = function (item) {
103
103
  'characterSpacing',
104
104
  'noWrap',
105
105
  'markerColor',
106
- 'leadingIndent'
106
+ 'leadingIndent',
107
+ 'sup',
108
+ 'sub'
107
109
  //'tableCellPadding'
108
110
  // 'cellBorder',
109
111
  // 'headerCellBorder',
package/src/textTools.js CHANGED
@@ -315,6 +315,13 @@ function measure(fontProvider, textArray, styleContextStack) {
315
315
  var preserveLeadingSpaces = getStyleProperty(item, styleContextStack, 'preserveLeadingSpaces', false);
316
316
  var preserveTrailingSpaces = getStyleProperty(item, styleContextStack, 'preserveTrailingSpaces', false);
317
317
  var opacity = getStyleProperty(item, styleContextStack, 'opacity', 1);
318
+ var sup = getStyleProperty(item, styleContextStack, 'sup', false);
319
+ var sub = getStyleProperty(item, styleContextStack, 'sub', false);
320
+
321
+ if ((sup || sub) && item.fontSize === undefined) {
322
+ // font size reduction taken from here: https://en.wikipedia.org/wiki/Subscript_and_superscript#Desktop_publishing
323
+ fontSize *= 0.58
324
+ }
318
325
 
319
326
  var font = fontProvider.provideFont(fontName, bold, italics);
320
327
 
@@ -352,6 +359,8 @@ function measure(fontProvider, textArray, styleContextStack) {
352
359
  item.linkToDestination = linkToDestination;
353
360
  item.noWrap = noWrap;
354
361
  item.opacity = opacity;
362
+ item.sup = sup;
363
+ item.sub = sub;
355
364
  });
356
365
 
357
366
  return normalized;
package/gulpfile.js DELETED
@@ -1,110 +0,0 @@
1
- var gulp = require('gulp');
2
- var webpack = require('webpack');
3
- var mocha = require('gulp-spawn-mocha');
4
- var eslint = require('gulp-eslint');
5
- var each = require('gulp-each');
6
- var fc2json = require('gulp-file-contents-to-json');
7
- var log = require('fancy-log');
8
- var exec = require('child_process').exec;
9
- const fs = require('fs');
10
-
11
- var DEBUG = process.env.NODE_ENV === 'debug';
12
- var CI = process.env.CI === 'true';
13
-
14
- var vfsBefore = "this.pdfMake = this.pdfMake || {}; this.pdfMake.vfs = ";
15
- var vfsAfter = ";";
16
-
17
- gulp.task('build', function (callback) {
18
- webpack(require('./webpack.config.js'), function (err, stats) {
19
- if (err) {
20
- callback(err);
21
- return;
22
- }
23
- log("[webpack]", stats.toString({}));
24
- if (stats.compilation.errors && stats.compilation.errors.length) {
25
- callback(stats.compilation.errors);
26
- return;
27
- }
28
- callback();
29
- });
30
- });
31
-
32
- gulp.task('buildWithStandardFonts', function (callback) {
33
- webpack(require('./webpack-standardfonts.config.js'), function (err, stats) {
34
- if (err) {
35
- callback(err);
36
- return;
37
- }
38
- log("[webpack]", stats.toString({}));
39
- if (stats.compilation.errors && stats.compilation.errors.length) {
40
- callback(stats.compilation.errors);
41
- return;
42
- }
43
- callback();
44
- });
45
- });
46
-
47
- gulp.task('test', function () {
48
- return gulp.src(['./tests/**/*.js'])
49
- .pipe(mocha({
50
- debugBrk: DEBUG,
51
- R: CI ? 'spec' : 'nyan'
52
- }));
53
- });
54
-
55
- gulp.task('lint', function () {
56
- return gulp.src(['./src/**/*.js'])
57
- .pipe(eslint())
58
- .pipe(eslint.format())
59
- .pipe(eslint.failAfterError());
60
- });
61
-
62
- gulp.task('buildFonts', function () {
63
- return gulp.src(['./examples/fonts/*.*'])
64
- .pipe(each(function (content, file, callback) {
65
- var newContent = Buffer.from(content).toString('base64');
66
- callback(null, newContent);
67
- }, 'buffer'))
68
- .pipe(fc2json('vfs_fonts.js', { flat: true }))
69
- .pipe(each(function (content, file, callback) {
70
- var newContent = vfsBefore + content + vfsAfter;
71
- callback(null, newContent);
72
- }, 'buffer'))
73
- .pipe(gulp.dest('build'));
74
- });
75
-
76
- gulp.task('watch', function () {
77
- gulp.watch('./src/**', ['test', 'build']);
78
- gulp.watch('./tests/**', ['test']);
79
- });
80
-
81
- gulp.task('generateExamples', function (cb) {
82
- var errCount = 0;
83
- var position = 0;
84
- process.chdir('examples');
85
-
86
- const items = fs.readdirSync('.');
87
- const files = items.filter(file => file.substring(file.length - 3, file.length) === '.js');
88
-
89
- files.forEach(function (file) {
90
- exec(`node ${file}`, function (err, stdout, stderr) {
91
- position++;
92
- log('FILE: ', file, ` (${position}/${files.length})`);
93
- log(stdout);
94
-
95
- if (err) {
96
- errCount++;
97
- log(stderr);
98
- }
99
-
100
- if (position === files.length) {
101
- if (errCount) {
102
- log('Errors count: ', errCount);
103
- }
104
- cb();
105
- }
106
- });
107
- });
108
- });
109
-
110
- gulp.task('default', gulp.series(/*'lint',*/ 'test', 'build', 'buildFonts'));
@@ -1,7 +0,0 @@
1
- var config = require("./webpack.config.js");
2
-
3
- var rule = {enforce: 'post', test: /pdfkit[/\\]js[/\\]/, loader: "transform-loader?brfs"};
4
-
5
- config.module.rules.push(rule);
6
-
7
- module.exports = config;
package/webpack.config.js DELETED
@@ -1,123 +0,0 @@
1
- var path = require('path');
2
- var UglifyJsPlugin = require('uglifyjs-webpack-plugin');
3
- var StringReplacePlugin = require("string-replace-webpack-plugin");
4
- var webpack = require('webpack');
5
- var pkg = require('./package.json');
6
-
7
- var banner = '/*! ' + pkg.name + ' v' + pkg.version + ', @license ' + pkg.license + ', @link ' + pkg.homepage + ' */';
8
-
9
- module.exports = {
10
- mode: 'production',
11
- entry: {
12
- 'pdfmake': './src/browser-extensions/pdfMake.js',
13
- 'pdfmake.min': './src/browser-extensions/pdfMake.js'
14
- },
15
- output: {
16
- path: path.join(__dirname, './build'),
17
- filename: '[name].js',
18
- libraryTarget: 'umd',
19
- // Workaround https://github.com/webpack/webpack/issues/6642 until https://github.com/webpack/webpack/issues/6525 lands.
20
- globalObject: `typeof self !== 'undefined' ? self : this`
21
- },
22
- resolve: {
23
- alias: {
24
- fs: path.join(__dirname, './src/browser-extensions/virtual-fs.js')
25
- }
26
- },
27
- node: {
28
- // Prevent webpack from injecting setImmediate polyfill, which includes a "new Function" through a global polyfill - which cannot be used in a CSP environment with sane defaults
29
- setImmediate: false
30
- },
31
- module: {
32
- rules: [
33
- // for fs don't use babel _interopDefault command
34
- {
35
- enforce: 'pre',
36
- test: /pdfkit[/\\]js[/\\]/,
37
- loader: StringReplacePlugin.replace({
38
- replacements: [
39
- {
40
- pattern: "import fs from 'fs';",
41
- replacement: function () {
42
- return "var fs = require('fs');";
43
- }
44
- }
45
- ]})
46
- },
47
- {
48
- test: /\.js$/,
49
- include: /(pdfkit|saslprep|unicode-trie|unicode-properties|dfa|linebreak|png-js)/,
50
- use: {
51
- loader: 'babel-loader',
52
- options: {
53
- presets: [
54
- [
55
- "@babel/preset-env",
56
- {
57
- targets: {
58
- "ie": "10"
59
- },
60
- modules: false,
61
- useBuiltIns: 'usage',
62
- // TODO: after fix in babel remove corejs version and remove core-js dependency in package.json
63
- corejs: "3.0.0",
64
- loose: true
65
- }
66
- ]
67
- ],
68
- plugins: ["@babel/plugin-transform-modules-commonjs"]
69
- }
70
- }
71
- },
72
- {
73
- test: /pdfMake.js$/,
74
- loader: 'expose-loader',
75
- options: {
76
- exposes: 'pdfMake',
77
- },
78
- include: [path.join(__dirname, './src/browser-extensions')]
79
- },
80
-
81
- /* temporary bugfix for FileSaver: added hack for mobile device support, see https://github.com/bpampuch/pdfmake/issues/1664 */
82
- /* waiting to merge and release PR https://github.com/eligrey/FileSaver.js/pull/533 */
83
- {test: /FileSaver.min.js$/, loader: StringReplacePlugin.replace({
84
- replacements: [
85
- {
86
- pattern: '"download"in HTMLAnchorElement.prototype',
87
- replacement: function () {
88
- return '(typeof HTMLAnchorElement !== "undefined" && "download" in HTMLAnchorElement.prototype)';
89
- }
90
- }
91
- ]})
92
- },
93
-
94
- {enforce: 'post', test: /fontkit[/\\]index.js$/, loader: "transform-loader?brfs"},
95
- {enforce: 'post', test: /unicode-properties[/\\]index.js$/, loader: "transform-loader?brfs"},
96
- {enforce: 'post', test: /linebreak[/\\]src[/\\]linebreaker.js/, loader: "transform-loader?brfs"}
97
- ]
98
- },
99
- optimization: {
100
- minimizer: [
101
- new UglifyJsPlugin({
102
- include: /\.min\.js$/,
103
- sourceMap: true,
104
- uglifyOptions: {
105
- compress: {
106
- drop_console: true
107
- },
108
- mangle: {
109
- reserved: ['HeadTable', 'NameTable', 'CmapTable', 'HheaTable', 'MaxpTable', 'HmtxTable', 'PostTable', 'OS2Table', 'LocaTable', 'GlyfTable']
110
- }
111
- }
112
- })
113
- ]
114
- },
115
- plugins: [
116
- new StringReplacePlugin(),
117
- new webpack.BannerPlugin({
118
- banner: banner,
119
- raw: true
120
- })
121
- ],
122
- devtool: 'source-map'
123
- };