pdfmake 0.3.0-beta.12 → 0.3.0-beta.13
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/CHANGELOG.md +9 -2
- package/build/pdfmake.js +600 -308
- package/build/pdfmake.js.map +1 -1
- package/build/pdfmake.min.js +2 -2
- package/build/pdfmake.min.js.map +1 -1
- package/build/vfs_fonts.js +6 -6
- package/js/DocMeasure.js +9 -0
- package/js/DocumentContext.js +13 -8
- package/js/ElementWriter.js +12 -3
- package/js/LayoutBuilder.js +33 -37
- package/js/PageElementWriter.js +15 -0
- package/js/Printer.js +7 -0
- package/js/Renderer.js +5 -14
- package/js/SVGMeasure.js +2 -2
- package/js/TextInlines.js +1 -1
- package/js/URLResolver.js +3 -0
- package/js/helpers/tools.js +6 -0
- package/package.json +2 -2
- package/src/3rd-party/svg-to-pdfkit/LICENSE +9 -9
- package/src/DocMeasure.js +8 -0
- package/src/DocumentContext.js +15 -13
- package/src/ElementWriter.js +11 -2
- package/src/LayoutBuilder.js +42 -43
- package/src/PageElementWriter.js +19 -0
- package/src/Printer.js +9 -0
- package/src/Renderer.js +3 -16
- package/src/SVGMeasure.js +2 -2
- package/src/TextInlines.js +1 -1
- package/src/URLResolver.js +4 -0
- package/src/helpers/tools.js +5 -0
- package/standard-fonts/Helvetica.js +0 -1
- package/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/pdfmake.iml +0 -11
- package/.idea/vcs.xml +0 -6
- package/eslint.config.mjs +0 -52
package/js/DocMeasure.js
CHANGED
|
@@ -117,6 +117,15 @@ class DocMeasure {
|
|
|
117
117
|
width: image.width,
|
|
118
118
|
height: image.height
|
|
119
119
|
};
|
|
120
|
+
if (image.constructor.name === 'JPEG') {
|
|
121
|
+
// If EXIF orientation calls for it, swap width and height
|
|
122
|
+
if (image.orientation > 4) {
|
|
123
|
+
imageSize = {
|
|
124
|
+
width: image.height,
|
|
125
|
+
height: image.width
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
}
|
|
120
129
|
this.measureImageWithDimensions(node, imageSize);
|
|
121
130
|
return node;
|
|
122
131
|
}
|
package/js/DocumentContext.js
CHANGED
|
@@ -9,17 +9,16 @@ var _events = require("events");
|
|
|
9
9
|
* It facilitates column divisions and vertical sync
|
|
10
10
|
*/
|
|
11
11
|
class DocumentContext extends _events.EventEmitter {
|
|
12
|
-
constructor(
|
|
12
|
+
constructor() {
|
|
13
13
|
super();
|
|
14
14
|
this.pages = [];
|
|
15
|
-
this.pageMargins =
|
|
16
|
-
this.x =
|
|
17
|
-
this.availableWidth =
|
|
18
|
-
this.availableHeight =
|
|
15
|
+
this.pageMargins = undefined;
|
|
16
|
+
this.x = undefined;
|
|
17
|
+
this.availableWidth = undefined;
|
|
18
|
+
this.availableHeight = undefined;
|
|
19
19
|
this.page = -1;
|
|
20
20
|
this.snapshots = [];
|
|
21
21
|
this.backgroundLength = [];
|
|
22
|
-
this.addPage(pageSize);
|
|
23
22
|
}
|
|
24
23
|
beginColumnGroup(marginXTopParent, bottomByPage = {}) {
|
|
25
24
|
this.snapshots.push({
|
|
@@ -220,10 +219,16 @@ class DocumentContext extends _events.EventEmitter {
|
|
|
220
219
|
y: this.y
|
|
221
220
|
};
|
|
222
221
|
}
|
|
223
|
-
addPage(pageSize) {
|
|
222
|
+
addPage(pageSize, pageMargin = null) {
|
|
223
|
+
if (pageMargin !== null) {
|
|
224
|
+
this.pageMargins = pageMargin;
|
|
225
|
+
this.x = pageMargin.left;
|
|
226
|
+
this.availableWidth = pageSize.width - pageMargin.left - pageMargin.right;
|
|
227
|
+
}
|
|
224
228
|
let page = {
|
|
225
229
|
items: [],
|
|
226
|
-
pageSize: pageSize
|
|
230
|
+
pageSize: pageSize,
|
|
231
|
+
pageMargins: this.pageMargins
|
|
227
232
|
};
|
|
228
233
|
this.pages.push(page);
|
|
229
234
|
this.backgroundLength.push(0);
|
package/js/ElementWriter.js
CHANGED
|
@@ -12,11 +12,18 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
12
12
|
* their positions based on the context
|
|
13
13
|
*/
|
|
14
14
|
class ElementWriter extends _events.EventEmitter {
|
|
15
|
+
/**
|
|
16
|
+
* @param {DocumentContext} context
|
|
17
|
+
*/
|
|
15
18
|
constructor(context) {
|
|
16
19
|
super();
|
|
17
20
|
this._context = context;
|
|
18
21
|
this.contextStack = [];
|
|
19
22
|
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @returns {DocumentContext}
|
|
26
|
+
*/
|
|
20
27
|
context() {
|
|
21
28
|
return this._context;
|
|
22
29
|
}
|
|
@@ -306,7 +313,7 @@ class ElementWriter extends _events.EventEmitter {
|
|
|
306
313
|
* pushContext(width, height) - creates and pushes a new context with the specified width and height
|
|
307
314
|
* pushContext() - creates a new context for unbreakable blocks (with current availableWidth and full-page-height)
|
|
308
315
|
*
|
|
309
|
-
* @param {
|
|
316
|
+
* @param {DocumentContext|number} contextOrWidth
|
|
310
317
|
* @param {number} height
|
|
311
318
|
*/
|
|
312
319
|
pushContext(contextOrWidth, height) {
|
|
@@ -315,8 +322,10 @@ class ElementWriter extends _events.EventEmitter {
|
|
|
315
322
|
contextOrWidth = this.context().availableWidth;
|
|
316
323
|
}
|
|
317
324
|
if ((0, _variableType.isNumber)(contextOrWidth)) {
|
|
318
|
-
|
|
319
|
-
|
|
325
|
+
let width = contextOrWidth;
|
|
326
|
+
contextOrWidth = new _DocumentContext.default();
|
|
327
|
+
contextOrWidth.addPage({
|
|
328
|
+
width: width,
|
|
320
329
|
height: height
|
|
321
330
|
}, {
|
|
322
331
|
left: 0,
|
package/js/LayoutBuilder.js
CHANGED
|
@@ -135,11 +135,11 @@ class LayoutBuilder {
|
|
|
135
135
|
this.linearNodeList = [];
|
|
136
136
|
docStructure = this.docPreprocessor.preprocessDocument(docStructure);
|
|
137
137
|
docStructure = this.docMeasure.measureDocument(docStructure);
|
|
138
|
-
this.writer = new _PageElementWriter.default(new _DocumentContext.default(
|
|
138
|
+
this.writer = new _PageElementWriter.default(new _DocumentContext.default());
|
|
139
139
|
this.writer.context().addListener('pageAdded', () => {
|
|
140
140
|
this.addBackground(background);
|
|
141
141
|
});
|
|
142
|
-
this.
|
|
142
|
+
this.writer.addPage(this.pageSize, null, this.pageMargins);
|
|
143
143
|
this.processNode(docStructure);
|
|
144
144
|
this.addHeadersAndFooters(header, footer);
|
|
145
145
|
if (watermark != null) {
|
|
@@ -163,18 +163,13 @@ class LayoutBuilder {
|
|
|
163
163
|
context.backgroundLength[context.page] += pageBackground.positions.length;
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
|
-
addStaticRepeatable(headerOrFooter, sizeFunction) {
|
|
167
|
-
this.addDynamicRepeatable(() =>
|
|
168
|
-
// copy to new object
|
|
169
|
-
JSON.parse(JSON.stringify(headerOrFooter)), sizeFunction);
|
|
170
|
-
}
|
|
171
166
|
addDynamicRepeatable(nodeGetter, sizeFunction) {
|
|
172
167
|
let pages = this.writer.context().pages;
|
|
173
168
|
for (let pageIndex = 0, l = pages.length; pageIndex < l; pageIndex++) {
|
|
174
169
|
this.writer.context().page = pageIndex;
|
|
175
170
|
let node = nodeGetter(pageIndex + 1, l, this.writer.context().pages[pageIndex].pageSize);
|
|
176
171
|
if (node) {
|
|
177
|
-
let sizes = sizeFunction(this.writer.context().getCurrentPage().pageSize, this.pageMargins);
|
|
172
|
+
let sizes = sizeFunction(this.writer.context().getCurrentPage().pageSize, this.writer.context().getCurrentPage().pageMargins);
|
|
178
173
|
this.writer.beginUnbreakableBlock(sizes.width, sizes.height);
|
|
179
174
|
node = this.docPreprocessor.preprocessDocument(node);
|
|
180
175
|
this.processNode(this.docMeasure.measureDocument(node));
|
|
@@ -195,15 +190,11 @@ class LayoutBuilder {
|
|
|
195
190
|
width: pageSize.width,
|
|
196
191
|
height: pageMargins.bottom
|
|
197
192
|
});
|
|
198
|
-
if (
|
|
193
|
+
if (header) {
|
|
199
194
|
this.addDynamicRepeatable(header, headerSizeFct);
|
|
200
|
-
} else if (header) {
|
|
201
|
-
this.addStaticRepeatable(header, headerSizeFct);
|
|
202
195
|
}
|
|
203
|
-
if (
|
|
196
|
+
if (footer) {
|
|
204
197
|
this.addDynamicRepeatable(footer, footerSizeFct);
|
|
205
|
-
} else if (footer) {
|
|
206
|
-
this.addStaticRepeatable(footer, footerSizeFct);
|
|
207
198
|
}
|
|
208
199
|
}
|
|
209
200
|
addWatermark(watermark, pdfDocument, defaultStyle) {
|
|
@@ -216,31 +207,36 @@ class LayoutBuilder {
|
|
|
216
207
|
// empty watermark text
|
|
217
208
|
return;
|
|
218
209
|
}
|
|
219
|
-
watermark.font = watermark.font || defaultStyle.font || 'Roboto';
|
|
220
|
-
watermark.fontSize = watermark.fontSize || 'auto';
|
|
221
|
-
watermark.color = watermark.color || 'black';
|
|
222
|
-
watermark.opacity = (0, _variableType.isNumber)(watermark.opacity) ? watermark.opacity : 0.6;
|
|
223
|
-
watermark.bold = watermark.bold || false;
|
|
224
|
-
watermark.italics = watermark.italics || false;
|
|
225
|
-
watermark.angle = (0, _variableType.isValue)(watermark.angle) ? watermark.angle : null;
|
|
226
|
-
if (watermark.angle === null) {
|
|
227
|
-
watermark.angle = Math.atan2(this.pageSize.height, this.pageSize.width) * -180 / Math.PI;
|
|
228
|
-
}
|
|
229
|
-
if (watermark.fontSize === 'auto') {
|
|
230
|
-
watermark.fontSize = getWatermarkFontSize(this.pageSize, watermark, pdfDocument);
|
|
231
|
-
}
|
|
232
|
-
let watermarkObject = {
|
|
233
|
-
text: watermark.text,
|
|
234
|
-
font: pdfDocument.provideFont(watermark.font, watermark.bold, watermark.italics),
|
|
235
|
-
fontSize: watermark.fontSize,
|
|
236
|
-
color: watermark.color,
|
|
237
|
-
opacity: watermark.opacity,
|
|
238
|
-
angle: watermark.angle
|
|
239
|
-
};
|
|
240
|
-
watermarkObject._size = getWatermarkSize(watermark, pdfDocument);
|
|
241
210
|
let pages = this.writer.context().pages;
|
|
242
211
|
for (let i = 0, l = pages.length; i < l; i++) {
|
|
243
|
-
pages[i].watermark =
|
|
212
|
+
pages[i].watermark = getWatermarkObject({
|
|
213
|
+
...watermark
|
|
214
|
+
}, pages[i].pageSize, pdfDocument, defaultStyle);
|
|
215
|
+
}
|
|
216
|
+
function getWatermarkObject(watermark, pageSize, pdfDocument, defaultStyle) {
|
|
217
|
+
watermark.font = watermark.font || defaultStyle.font || 'Roboto';
|
|
218
|
+
watermark.fontSize = watermark.fontSize || 'auto';
|
|
219
|
+
watermark.color = watermark.color || 'black';
|
|
220
|
+
watermark.opacity = (0, _variableType.isNumber)(watermark.opacity) ? watermark.opacity : 0.6;
|
|
221
|
+
watermark.bold = watermark.bold || false;
|
|
222
|
+
watermark.italics = watermark.italics || false;
|
|
223
|
+
watermark.angle = (0, _variableType.isValue)(watermark.angle) ? watermark.angle : null;
|
|
224
|
+
if (watermark.angle === null) {
|
|
225
|
+
watermark.angle = Math.atan2(pageSize.height, pageSize.width) * -180 / Math.PI;
|
|
226
|
+
}
|
|
227
|
+
if (watermark.fontSize === 'auto') {
|
|
228
|
+
watermark.fontSize = getWatermarkFontSize(pageSize, watermark, pdfDocument);
|
|
229
|
+
}
|
|
230
|
+
let watermarkObject = {
|
|
231
|
+
text: watermark.text,
|
|
232
|
+
font: pdfDocument.provideFont(watermark.font, watermark.bold, watermark.italics),
|
|
233
|
+
fontSize: watermark.fontSize,
|
|
234
|
+
color: watermark.color,
|
|
235
|
+
opacity: watermark.opacity,
|
|
236
|
+
angle: watermark.angle
|
|
237
|
+
};
|
|
238
|
+
watermarkObject._size = getWatermarkSize(watermark, pdfDocument);
|
|
239
|
+
return watermarkObject;
|
|
244
240
|
}
|
|
245
241
|
function getWatermarkSize(watermark, pdfDocument) {
|
|
246
242
|
let textInlines = new _TextInlines.default(pdfDocument);
|
package/js/PageElementWriter.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
exports.default = void 0;
|
|
5
5
|
var _ElementWriter = _interopRequireDefault(require("./ElementWriter"));
|
|
6
|
+
var _PageSize = require("./PageSize");
|
|
7
|
+
var _DocumentContext = _interopRequireDefault(require("./DocumentContext"));
|
|
6
8
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
9
|
/**
|
|
8
10
|
* An extended ElementWriter which can handle:
|
|
@@ -13,6 +15,9 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
13
15
|
* whole block will be rendered on the same page)
|
|
14
16
|
*/
|
|
15
17
|
class PageElementWriter extends _ElementWriter.default {
|
|
18
|
+
/**
|
|
19
|
+
* @param {DocumentContext} context
|
|
20
|
+
*/
|
|
16
21
|
constructor(context) {
|
|
17
22
|
super(context);
|
|
18
23
|
this.transactionLevel = 0;
|
|
@@ -68,6 +73,16 @@ class PageElementWriter extends _ElementWriter.default {
|
|
|
68
73
|
y: this.context().y
|
|
69
74
|
});
|
|
70
75
|
}
|
|
76
|
+
addPage(pageSize, pageOrientation, pageMargin) {
|
|
77
|
+
let prevPage = this.page;
|
|
78
|
+
let prevY = this.y;
|
|
79
|
+
this.context().addPage((0, _PageSize.normalizePageSize)(pageSize, pageOrientation), (0, _PageSize.normalizePageMargin)(pageMargin));
|
|
80
|
+
this.emit('pageChanged', {
|
|
81
|
+
prevPage: prevPage,
|
|
82
|
+
prevY: prevY,
|
|
83
|
+
y: this.context().y
|
|
84
|
+
});
|
|
85
|
+
}
|
|
71
86
|
beginUnbreakableBlock(width, height) {
|
|
72
87
|
if (this.transactionLevel++ === 0) {
|
|
73
88
|
this.originalX = this.context().x;
|
package/js/Printer.js
CHANGED
|
@@ -9,6 +9,7 @@ var _PageSize = require("./PageSize");
|
|
|
9
9
|
var _tableLayouts = require("./tableLayouts");
|
|
10
10
|
var _Renderer = _interopRequireDefault(require("./Renderer"));
|
|
11
11
|
var _variableType = require("./helpers/variableType");
|
|
12
|
+
var _tools = require("./helpers/tools");
|
|
12
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
14
|
/**
|
|
14
15
|
* Printer which turns document definition into a pdf
|
|
@@ -58,6 +59,12 @@ class PdfPrinter {
|
|
|
58
59
|
docDefinition.attachments = docDefinition.attachments || {};
|
|
59
60
|
docDefinition.pageMargins = (0, _variableType.isValue)(docDefinition.pageMargins) ? docDefinition.pageMargins : 40;
|
|
60
61
|
docDefinition.patterns = docDefinition.patterns || {};
|
|
62
|
+
if (docDefinition.header && typeof docDefinition.header !== 'function') {
|
|
63
|
+
docDefinition.header = (0, _tools.convertToDynamicContent)(docDefinition.header);
|
|
64
|
+
}
|
|
65
|
+
if (docDefinition.footer && typeof docDefinition.footer !== 'function') {
|
|
66
|
+
docDefinition.footer = (0, _tools.convertToDynamicContent)(docDefinition.footer);
|
|
67
|
+
}
|
|
61
68
|
let pageSize = (0, _PageSize.normalizePageSize)(docDefinition.pageSize, docDefinition.pageOrientation);
|
|
62
69
|
let pdfOptions = {
|
|
63
70
|
size: [pageSize.width, pageSize.height],
|
package/js/Renderer.js
CHANGED
|
@@ -29,7 +29,7 @@ const findFont = (fonts, requiredFonts, defaultFont) => {
|
|
|
29
29
|
* @returns {number}
|
|
30
30
|
*/
|
|
31
31
|
const offsetText = (y, inline) => {
|
|
32
|
-
|
|
32
|
+
let newY = y;
|
|
33
33
|
if (inline.sup) {
|
|
34
34
|
newY -= inline.fontSize * 0.75;
|
|
35
35
|
}
|
|
@@ -45,7 +45,7 @@ class Renderer {
|
|
|
45
45
|
}
|
|
46
46
|
renderPages(pages) {
|
|
47
47
|
this.pdfDocument._pdfMakePages = pages; // TODO: Why?
|
|
48
|
-
|
|
48
|
+
|
|
49
49
|
let totalItems = 0;
|
|
50
50
|
if (this.progressCallback) {
|
|
51
51
|
pages.forEach(page => {
|
|
@@ -54,10 +54,9 @@ class Renderer {
|
|
|
54
54
|
}
|
|
55
55
|
let renderedItems = 0;
|
|
56
56
|
for (let i = 0; i < pages.length; i++) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
57
|
+
this.pdfDocument.addPage({
|
|
58
|
+
size: [pages[i].pageSize.width, pages[i].pageSize.height]
|
|
59
|
+
});
|
|
61
60
|
let page = pages[i];
|
|
62
61
|
for (let ii = 0, il = page.items.length; ii < il; ii++) {
|
|
63
62
|
let item = page.items[ii];
|
|
@@ -380,13 +379,5 @@ class Renderer {
|
|
|
380
379
|
});
|
|
381
380
|
this.pdfDocument.restore();
|
|
382
381
|
}
|
|
383
|
-
_updatePageOrientationInOptions(currentPage) {
|
|
384
|
-
let previousPageOrientation = this.pdfDocument.options.size[0] > this.pdfDocument.options.size[1] ? 'landscape' : 'portrait';
|
|
385
|
-
if (currentPage.pageSize.orientation !== previousPageOrientation) {
|
|
386
|
-
let width = this.pdfDocument.options.size[0];
|
|
387
|
-
let height = this.pdfDocument.options.size[1];
|
|
388
|
-
this.pdfDocument.options.size = [height, width];
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
382
|
}
|
|
392
383
|
var _default = exports.default = Renderer;
|
package/js/SVGMeasure.js
CHANGED
|
@@ -11,7 +11,7 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
11
11
|
* @returns {?number}
|
|
12
12
|
*/
|
|
13
13
|
const stripUnits = textVal => {
|
|
14
|
-
|
|
14
|
+
let n = parseFloat(textVal);
|
|
15
15
|
if (typeof n !== 'number' || isNaN(n)) {
|
|
16
16
|
return undefined;
|
|
17
17
|
}
|
|
@@ -25,7 +25,7 @@ const stripUnits = textVal => {
|
|
|
25
25
|
* @returns {object}
|
|
26
26
|
*/
|
|
27
27
|
const parseSVG = svgString => {
|
|
28
|
-
|
|
28
|
+
let doc;
|
|
29
29
|
try {
|
|
30
30
|
doc = new _xmldoc.default.XmlDocument(svgString);
|
|
31
31
|
} catch (err) {
|
package/js/TextInlines.js
CHANGED
|
@@ -45,7 +45,7 @@ class TextInlines {
|
|
|
45
45
|
* Converts an array of strings (or inline-definition-objects) into a collection
|
|
46
46
|
* of inlines and calculated minWidth/maxWidth and their min/max widths
|
|
47
47
|
*
|
|
48
|
-
* @param {Array} textArray an array of inline-definition-objects (or strings)
|
|
48
|
+
* @param {Array|object} textArray an array of inline-definition-objects (or strings)
|
|
49
49
|
* @param {StyleContextStack} styleContextStack current style stack
|
|
50
50
|
* @returns {object} collection of inlines, minWidth, maxWidth
|
|
51
51
|
*/
|
package/js/URLResolver.js
CHANGED
|
@@ -15,6 +15,7 @@ const fetchUrl = (url, headers = {}) => {
|
|
|
15
15
|
h.get(url, options, res => {
|
|
16
16
|
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
17
17
|
// redirect url
|
|
18
|
+
res.resume();
|
|
18
19
|
fetchUrl(res.headers.location).then(buffer => {
|
|
19
20
|
resolve(buffer);
|
|
20
21
|
}, result => {
|
|
@@ -25,6 +26,8 @@ const fetchUrl = (url, headers = {}) => {
|
|
|
25
26
|
const ok = res.statusCode >= 200 && res.statusCode < 300;
|
|
26
27
|
if (!ok) {
|
|
27
28
|
reject(new TypeError(`Failed to fetch (status code: ${res.statusCode}, url: "${url}")`));
|
|
29
|
+
res.resume();
|
|
30
|
+
return;
|
|
28
31
|
}
|
|
29
32
|
const chunks = [];
|
|
30
33
|
res.on('end', () => resolve(Buffer.concat(chunks)));
|
package/js/helpers/tools.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
|
+
exports.convertToDynamicContent = convertToDynamicContent;
|
|
4
5
|
exports.offsetVector = offsetVector;
|
|
5
6
|
exports.pack = pack;
|
|
6
7
|
function pack(...args) {
|
|
@@ -37,4 +38,9 @@ function offsetVector(vector, x, y) {
|
|
|
37
38
|
}
|
|
38
39
|
break;
|
|
39
40
|
}
|
|
41
|
+
}
|
|
42
|
+
function convertToDynamicContent(staticContent) {
|
|
43
|
+
return () =>
|
|
44
|
+
// copy to new object
|
|
45
|
+
JSON.parse(JSON.stringify(staticContent));
|
|
40
46
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pdfmake",
|
|
3
|
-
"version": "0.3.0-beta.
|
|
3
|
+
"version": "0.3.0-beta.13",
|
|
4
4
|
"description": "Client/server side PDF printing in pure JavaScript",
|
|
5
5
|
"main": "js/index.js",
|
|
6
6
|
"esnext": "src/index.js",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@foliojs-fork/linebreak": "^1.1.2",
|
|
13
|
-
"@foliojs-fork/pdfkit": "^0.15.
|
|
13
|
+
"@foliojs-fork/pdfkit": "^0.15.2",
|
|
14
14
|
"iconv-lite": "^0.6.3",
|
|
15
15
|
"xmldoc": "^1.3.0"
|
|
16
16
|
},
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2019 SVG-to-PDFKit contributors
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
-
|
|
7
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
-
|
|
9
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 SVG-to-PDFKit contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/src/DocMeasure.js
CHANGED
|
@@ -128,8 +128,16 @@ class DocMeasure {
|
|
|
128
128
|
this.convertIfBase64Image(node);
|
|
129
129
|
|
|
130
130
|
let image = this.pdfDocument.provideImage(node.image);
|
|
131
|
+
|
|
131
132
|
let imageSize = { width: image.width, height: image.height };
|
|
132
133
|
|
|
134
|
+
if (image.constructor.name === 'JPEG') {
|
|
135
|
+
// If EXIF orientation calls for it, swap width and height
|
|
136
|
+
if (image.orientation > 4) {
|
|
137
|
+
imageSize = { width: image.height, height: image.width };
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
133
141
|
this.measureImageWithDimensions(node, imageSize);
|
|
134
142
|
|
|
135
143
|
return node;
|
package/src/DocumentContext.js
CHANGED
|
@@ -6,21 +6,17 @@ import { EventEmitter } from 'events';
|
|
|
6
6
|
* It facilitates column divisions and vertical sync
|
|
7
7
|
*/
|
|
8
8
|
class DocumentContext extends EventEmitter {
|
|
9
|
-
constructor(
|
|
9
|
+
constructor() {
|
|
10
10
|
super();
|
|
11
11
|
this.pages = [];
|
|
12
|
-
|
|
13
|
-
this.
|
|
14
|
-
|
|
15
|
-
this.
|
|
16
|
-
this.availableWidth = pageSize.width - pageMargins.left - pageMargins.right;
|
|
17
|
-
this.availableHeight = 0;
|
|
12
|
+
this.pageMargins = undefined;
|
|
13
|
+
this.x = undefined;
|
|
14
|
+
this.availableWidth = undefined;
|
|
15
|
+
this.availableHeight = undefined;
|
|
18
16
|
this.page = -1;
|
|
19
17
|
|
|
20
18
|
this.snapshots = [];
|
|
21
19
|
this.backgroundLength = [];
|
|
22
|
-
|
|
23
|
-
this.addPage(pageSize);
|
|
24
20
|
}
|
|
25
21
|
|
|
26
22
|
beginColumnGroup(marginXTopParent, bottomByPage = {}) {
|
|
@@ -30,7 +26,7 @@ class DocumentContext extends EventEmitter {
|
|
|
30
26
|
availableHeight: this.availableHeight,
|
|
31
27
|
availableWidth: this.availableWidth,
|
|
32
28
|
page: this.page,
|
|
33
|
-
|
|
29
|
+
bottomByPage: bottomByPage ? bottomByPage : {},
|
|
34
30
|
bottomMost: {
|
|
35
31
|
x: this.x,
|
|
36
32
|
y: this.y,
|
|
@@ -47,7 +43,7 @@ class DocumentContext extends EventEmitter {
|
|
|
47
43
|
}
|
|
48
44
|
}
|
|
49
45
|
|
|
50
|
-
updateBottomByPage
|
|
46
|
+
updateBottomByPage() {
|
|
51
47
|
const lastSnapshot = this.snapshots[this.snapshots.length - 1];
|
|
52
48
|
const lastPage = this.page;
|
|
53
49
|
let previousBottom = -Number.MIN_VALUE;
|
|
@@ -244,8 +240,14 @@ class DocumentContext extends EventEmitter {
|
|
|
244
240
|
};
|
|
245
241
|
}
|
|
246
242
|
|
|
247
|
-
addPage(pageSize) {
|
|
248
|
-
|
|
243
|
+
addPage(pageSize, pageMargin = null) {
|
|
244
|
+
if (pageMargin !== null) {
|
|
245
|
+
this.pageMargins = pageMargin;
|
|
246
|
+
this.x = pageMargin.left;
|
|
247
|
+
this.availableWidth = pageSize.width - pageMargin.left - pageMargin.right;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
let page = { items: [], pageSize: pageSize, pageMargins: this.pageMargins };
|
|
249
251
|
this.pages.push(page);
|
|
250
252
|
this.backgroundLength.push(0);
|
|
251
253
|
this.page = this.pages.length - 1;
|
package/src/ElementWriter.js
CHANGED
|
@@ -8,12 +8,19 @@ import { EventEmitter } from 'events';
|
|
|
8
8
|
* their positions based on the context
|
|
9
9
|
*/
|
|
10
10
|
class ElementWriter extends EventEmitter {
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @param {DocumentContext} context
|
|
14
|
+
*/
|
|
11
15
|
constructor(context) {
|
|
12
16
|
super();
|
|
13
17
|
this._context = context;
|
|
14
18
|
this.contextStack = [];
|
|
15
19
|
}
|
|
16
20
|
|
|
21
|
+
/**
|
|
22
|
+
* @returns {DocumentContext}
|
|
23
|
+
*/
|
|
17
24
|
context() {
|
|
18
25
|
return this._context;
|
|
19
26
|
}
|
|
@@ -371,7 +378,7 @@ class ElementWriter extends EventEmitter {
|
|
|
371
378
|
* pushContext(width, height) - creates and pushes a new context with the specified width and height
|
|
372
379
|
* pushContext() - creates a new context for unbreakable blocks (with current availableWidth and full-page-height)
|
|
373
380
|
*
|
|
374
|
-
* @param {
|
|
381
|
+
* @param {DocumentContext|number} contextOrWidth
|
|
375
382
|
* @param {number} height
|
|
376
383
|
*/
|
|
377
384
|
pushContext(contextOrWidth, height) {
|
|
@@ -381,7 +388,9 @@ class ElementWriter extends EventEmitter {
|
|
|
381
388
|
}
|
|
382
389
|
|
|
383
390
|
if (isNumber(contextOrWidth)) {
|
|
384
|
-
|
|
391
|
+
let width = contextOrWidth;
|
|
392
|
+
contextOrWidth = new DocumentContext();
|
|
393
|
+
contextOrWidth.addPage({ width: width, height: height }, { left: 0, right: 0, top: 0, bottom: 0 });
|
|
385
394
|
}
|
|
386
395
|
|
|
387
396
|
this.contextStack.push(this.context());
|