@wirabyte/w-pdfmaker 0.0.0-stage → 1.0.2
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 +53 -0
- package/LICENSE +22 -0
- package/NOTICE.md +39 -0
- package/README.md +106 -2
- package/build/fonts/Roboto/Roboto-Italic.ttf +0 -0
- package/build/fonts/Roboto/Roboto-Medium.ttf +0 -0
- package/build/fonts/Roboto/Roboto-MediumItalic.ttf +0 -0
- package/build/fonts/Roboto/Roboto-Regular.ttf +0 -0
- package/build/fonts/Roboto.js +27 -0
- package/build/pdfmake.js +103161 -0
- package/build/pdfmake.js.map +1 -0
- package/build/pdfmake.min.js +3 -0
- package/build/pdfmake.min.js.map +1 -0
- package/build/standard-fonts/Courier.js +9 -0
- package/build/standard-fonts/Helvetica.js +9 -0
- package/build/standard-fonts/Symbol.js +9 -0
- package/build/standard-fonts/Times.js +9 -0
- package/build/standard-fonts/ZapfDingbats.js +9 -0
- package/build/vfs_fonts.js +6 -0
- package/build-vfs.js +44 -0
- package/fonts/Roboto/Roboto-Italic.ttf +0 -0
- package/fonts/Roboto/Roboto-Medium.ttf +0 -0
- package/fonts/Roboto/Roboto-MediumItalic.ttf +0 -0
- package/fonts/Roboto/Roboto-Regular.ttf +0 -0
- package/fonts/Roboto.js +8 -0
- package/fonts/THSarabunIT9/LICENSE.txt +7 -0
- package/fonts/THSarabunIT9/THSarabunIT9-Bold.ttf +0 -0
- package/fonts/THSarabunIT9/THSarabunIT9-BoldItalic.ttf +0 -0
- package/fonts/THSarabunIT9/THSarabunIT9-Italic.ttf +0 -0
- package/fonts/THSarabunIT9/THSarabunIT9.ttf +0 -0
- package/fonts/THSarabunNew/COPYING.GPLv2 +339 -0
- package/fonts/THSarabunNew/LICENSE.txt +13 -0
- package/fonts/THSarabunNew/THSarabunNew-Bold.ttf +0 -0
- package/fonts/THSarabunNew/THSarabunNew-BoldItalic.ttf +0 -0
- package/fonts/THSarabunNew/THSarabunNew-Italic.ttf +0 -0
- package/fonts/THSarabunNew/THSarabunNew.ttf +0 -0
- package/index.d.ts +167 -0
- package/interfaces.d.ts +2779 -0
- package/js/DocMeasure.js +695 -0
- package/js/DocPreprocessor.js +263 -0
- package/js/DocumentContext.js +563 -0
- package/js/ElementWriter.js +488 -0
- package/js/LayoutBuilder.js +1525 -0
- package/js/Line.js +105 -0
- package/js/OutputDocument.js +73 -0
- package/js/OutputDocumentServer.js +34 -0
- package/js/PDFDocument.js +322 -0
- package/js/PageElementWriter.js +302 -0
- package/js/PageSize.js +74 -0
- package/js/Printer.js +275 -0
- package/js/Renderer.js +439 -0
- package/js/SVGMeasure.js +94 -0
- package/js/StyleContextStack.js +191 -0
- package/js/TableProcessor.js +658 -0
- package/js/TextBreaker.js +164 -0
- package/js/TextDecorator.js +164 -0
- package/js/TextInlines.js +212 -0
- package/js/URLResolver.js +122 -0
- package/js/base.js +125 -0
- package/js/browser-extensions/OutputDocumentBrowser.js +82 -0
- package/js/browser-extensions/fonts/Roboto.js +38 -0
- package/js/browser-extensions/fonts/thai.js +28 -0
- package/js/browser-extensions/index.js +88 -0
- package/js/browser-extensions/pageUrls.js +79 -0
- package/js/browser-extensions/pdfMake.js +3 -0
- package/js/browser-extensions/standard-fonts/Courier.js +20 -0
- package/js/browser-extensions/standard-fonts/Helvetica.js +20 -0
- package/js/browser-extensions/standard-fonts/Symbol.js +17 -0
- package/js/browser-extensions/standard-fonts/Times.js +20 -0
- package/js/browser-extensions/standard-fonts/ZapfDingbats.js +17 -0
- package/js/browser-extensions/virtual-fs-cjs.js +3 -0
- package/js/columnCalculator.js +159 -0
- package/js/helpers/node.js +122 -0
- package/js/helpers/tools.js +46 -0
- package/js/helpers/variableType.js +59 -0
- package/js/imageFallback.js +23 -0
- package/js/index.js +45 -0
- package/js/mergeStamp.js +194 -0
- package/js/pageNumbering.js +48 -0
- package/js/qrEnc.js +721 -0
- package/js/standardPageSizes.js +56 -0
- package/js/tableLayouts.js +98 -0
- package/js/thai.js +201 -0
- package/js/virtual-fs.js +82 -0
- package/package.json +93 -4
- package/skills/w-pdfmaker/SKILL.md +171 -0
- package/skills/w-pdfmaker/references/browser.md +36 -0
- package/skills/w-pdfmaker/references/document-definition.md +241 -0
- package/skills/w-pdfmaker/references/images.md +90 -0
- package/skills/w-pdfmaker/references/merge-stamp.md +94 -0
- package/skills/w-pdfmaker/references/thai.md +67 -0
- package/src/DocMeasure.js +780 -0
- package/src/DocPreprocessor.js +293 -0
- package/src/DocumentContext.js +605 -0
- package/src/ElementWriter.js +550 -0
- package/src/LayoutBuilder.js +1689 -0
- package/src/Line.js +114 -0
- package/src/OutputDocument.js +75 -0
- package/src/OutputDocumentServer.js +38 -0
- package/src/PDFDocument.js +352 -0
- package/src/PageElementWriter.js +343 -0
- package/src/PageSize.js +53 -0
- package/src/Printer.js +289 -0
- package/src/Renderer.js +468 -0
- package/src/SVGMeasure.js +109 -0
- package/src/StyleContextStack.js +208 -0
- package/src/TableProcessor.js +719 -0
- package/src/TextBreaker.js +166 -0
- package/src/TextDecorator.js +191 -0
- package/src/TextInlines.js +229 -0
- package/src/URLResolver.js +122 -0
- package/src/base.js +143 -0
- package/src/browser-extensions/OutputDocumentBrowser.js +80 -0
- package/src/browser-extensions/fonts/Roboto.js +27 -0
- package/src/browser-extensions/fonts/thai.js +23 -0
- package/src/browser-extensions/index.js +91 -0
- package/src/browser-extensions/pageUrls.js +67 -0
- package/src/browser-extensions/pdfMake.js +1 -0
- package/src/browser-extensions/standard-fonts/Courier.js +25 -0
- package/src/browser-extensions/standard-fonts/Helvetica.js +25 -0
- package/src/browser-extensions/standard-fonts/Symbol.js +17 -0
- package/src/browser-extensions/standard-fonts/Times.js +25 -0
- package/src/browser-extensions/standard-fonts/ZapfDingbats.js +17 -0
- package/src/browser-extensions/virtual-fs-cjs.js +1 -0
- package/src/columnCalculator.js +160 -0
- package/src/helpers/node.js +134 -0
- package/src/helpers/tools.js +44 -0
- package/src/helpers/variableType.js +50 -0
- package/src/imageFallback.js +18 -0
- package/src/index.js +45 -0
- package/src/mergeStamp.js +132 -0
- package/src/pageNumbering.js +45 -0
- package/src/qrEnc.js +796 -0
- package/src/standardPageSizes.js +52 -0
- package/src/tableLayouts.js +100 -0
- package/src/thai.js +170 -0
- package/src/virtual-fs.js +92 -0
- package/standard-fonts/Courier.js +8 -0
- package/standard-fonts/Helvetica.js +8 -0
- package/standard-fonts/Symbol.js +5 -0
- package/standard-fonts/Times.js +8 -0
- package/standard-fonts/ZapfDingbats.js +5 -0
package/js/base.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = void 0;
|
|
5
|
+
var _Printer = _interopRequireDefault(require("./Printer"));
|
|
6
|
+
var _virtualFs = _interopRequireWildcard(require("./virtual-fs"));
|
|
7
|
+
var _tools = require("./helpers/tools");
|
|
8
|
+
var _variableType = require("./helpers/variableType");
|
|
9
|
+
var _URLResolver = _interopRequireDefault(require("./URLResolver"));
|
|
10
|
+
var _thai = require("./thai");
|
|
11
|
+
var _mergeStamp = require("./mergeStamp");
|
|
12
|
+
var cache;
|
|
13
|
+
function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var r, c, a = Object.defineProperty, n = { __proto__: null, default: e }; if (Object(e) !== e) return n; if (cache || "function" != typeof WeakMap || (cache = new WeakMap()), cache) { if (cache.has(e)) return cache.get(e); cache.set(e, n); } for (c in e) "default" !== c && {}.hasOwnProperty.call(e, c) && ((r = a && Object.getOwnPropertyDescriptor(e, c)) && (r.get || r.set) ? a(n, c, r) : n[c] = e[c]); return n; }
|
|
14
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
|
+
class pdfmake {
|
|
16
|
+
constructor() {
|
|
17
|
+
this.sharedVirtualfs = _virtualFs.default;
|
|
18
|
+
this.urlResourceCaching = false;
|
|
19
|
+
this.urlAccessPolicy = undefined;
|
|
20
|
+
this.localAccessPolicy = undefined;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @param {object} docDefinition
|
|
25
|
+
* @param {?object} options
|
|
26
|
+
* @returns {object}
|
|
27
|
+
*/
|
|
28
|
+
createPdf(docDefinition, options = {}) {
|
|
29
|
+
if (!(0, _variableType.isObject)(docDefinition)) {
|
|
30
|
+
throw new Error("Parameter 'docDefinition' has an invalid type. Object expected.");
|
|
31
|
+
}
|
|
32
|
+
if (!(0, _variableType.isObject)(options)) {
|
|
33
|
+
throw new Error("Parameter 'options' has an invalid type. Object expected.");
|
|
34
|
+
}
|
|
35
|
+
docDefinition = (0, _thai.withThaiDefaults)(docDefinition, this.fonts);
|
|
36
|
+
options.progressCallback = this.progressCallback;
|
|
37
|
+
options.tableLayouts = this.tableLayouts;
|
|
38
|
+
const isServer = typeof process !== 'undefined' && process?.versions?.node;
|
|
39
|
+
if (typeof this.urlAccessPolicy === 'undefined' && isServer) {
|
|
40
|
+
console.warn('No URL access policy defined. Consider using setUrlAccessPolicy() to restrict external resource downloads.');
|
|
41
|
+
}
|
|
42
|
+
if (typeof this.localAccessPolicy === 'undefined' && isServer) {
|
|
43
|
+
console.warn('No local access policy defined. Consider using setLocalAccessPolicy() to restrict local file system access.');
|
|
44
|
+
}
|
|
45
|
+
const documentVirtualfs = new _virtualFs.VirtualFileSystem(this.sharedVirtualfs);
|
|
46
|
+
let urlResolver = new _URLResolver.default(documentVirtualfs, this.sharedVirtualfs);
|
|
47
|
+
urlResolver.setUrlAccessPolicy(this.urlAccessPolicy);
|
|
48
|
+
let printer = new _Printer.default(this.fonts, documentVirtualfs, urlResolver, this.localAccessPolicy, this.urlResourceCaching);
|
|
49
|
+
const pdfDocumentPromise = printer.createPdfKitDocument(docDefinition, options);
|
|
50
|
+
return this._transformToDocument(pdfDocumentPromise);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @param {(url: string) => boolean} callback
|
|
55
|
+
*/
|
|
56
|
+
setUrlAccessPolicy(callback) {
|
|
57
|
+
if (callback !== undefined && typeof callback !== 'function') {
|
|
58
|
+
throw new Error("Parameter 'callback' has an invalid type. Function or undefined expected.");
|
|
59
|
+
}
|
|
60
|
+
this.urlAccessPolicy = callback;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @param {boolean} enabled
|
|
65
|
+
*/
|
|
66
|
+
setUrlResourceCaching(enabled) {
|
|
67
|
+
if (typeof enabled !== 'boolean') {
|
|
68
|
+
throw new Error("Parameter 'enabled' has an invalid type. Boolean expected.");
|
|
69
|
+
}
|
|
70
|
+
this.urlResourceCaching = enabled;
|
|
71
|
+
}
|
|
72
|
+
clearUrlResourceCache() {
|
|
73
|
+
for (const filename of Object.keys(this.sharedVirtualfs.storage)) {
|
|
74
|
+
if (/^https?:\/\//i.test(filename)) {
|
|
75
|
+
this.sharedVirtualfs.unlinkSync(filename);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
setProgressCallback(callback) {
|
|
80
|
+
this.progressCallback = callback;
|
|
81
|
+
}
|
|
82
|
+
addTableLayouts(tableLayouts) {
|
|
83
|
+
this.tableLayouts = (0, _tools.pack)(this.tableLayouts, tableLayouts);
|
|
84
|
+
}
|
|
85
|
+
setTableLayouts(tableLayouts) {
|
|
86
|
+
this.tableLayouts = tableLayouts;
|
|
87
|
+
}
|
|
88
|
+
clearTableLayouts() {
|
|
89
|
+
this.tableLayouts = {};
|
|
90
|
+
}
|
|
91
|
+
addFonts(fonts) {
|
|
92
|
+
this.fonts = (0, _tools.pack)(this.fonts, fonts);
|
|
93
|
+
}
|
|
94
|
+
setFonts(fonts) {
|
|
95
|
+
this.fonts = fonts;
|
|
96
|
+
}
|
|
97
|
+
clearFonts() {
|
|
98
|
+
this.fonts = {};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* w-pdfmaker: joins pages of PDFs in order.
|
|
103
|
+
*
|
|
104
|
+
* @param {Array<Buffer|Uint8Array|string|{pdf: Buffer|Uint8Array|string, from?: number, to?: number}>} parts
|
|
105
|
+
* @returns {Promise<Buffer>}
|
|
106
|
+
*/
|
|
107
|
+
merge(parts) {
|
|
108
|
+
return (0, _mergeStamp.merge)(parts, path => this._readFile(path));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* w-pdfmaker: draws pdfmake content over the pages of an existing PDF.
|
|
113
|
+
*
|
|
114
|
+
* @param {Buffer|Uint8Array|string} pdf
|
|
115
|
+
* @param {Function} fn ({ pageNumber, pageCount, width, height }) => content, or null to skip the page
|
|
116
|
+
* @returns {Promise<Buffer>}
|
|
117
|
+
*/
|
|
118
|
+
stamp(pdf, fn) {
|
|
119
|
+
return (0, _mergeStamp.stamp)(pdf, fn, docDefinition => this.createPdf(docDefinition).getBuffer(), path => this._readFile(path));
|
|
120
|
+
}
|
|
121
|
+
_transformToDocument(doc) {
|
|
122
|
+
return doc;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
var _default = exports.default = pdfmake;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = void 0;
|
|
5
|
+
var _OutputDocument = _interopRequireDefault(require("../OutputDocument"));
|
|
6
|
+
var _fileSaver = require("file-saver");
|
|
7
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
|
+
/**
|
|
9
|
+
* @returns {Window}
|
|
10
|
+
*/
|
|
11
|
+
const openWindow = () => {
|
|
12
|
+
// we have to open the window immediately and store the reference
|
|
13
|
+
// otherwise popup blockers will stop us
|
|
14
|
+
let win = window.open('', '_blank');
|
|
15
|
+
if (win === null) {
|
|
16
|
+
throw new Error('Open PDF in new window blocked by browser');
|
|
17
|
+
}
|
|
18
|
+
return win;
|
|
19
|
+
};
|
|
20
|
+
class OutputDocumentBrowser extends _OutputDocument.default {
|
|
21
|
+
/**
|
|
22
|
+
* @returns {Promise<Blob>}
|
|
23
|
+
*/
|
|
24
|
+
async getBlob() {
|
|
25
|
+
const buffer = await this.getBuffer();
|
|
26
|
+
return new Blob([buffer], {
|
|
27
|
+
type: 'application/pdf'
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @param {string} filename
|
|
33
|
+
* @returns {Promise}
|
|
34
|
+
*/
|
|
35
|
+
async download(filename = 'file.pdf') {
|
|
36
|
+
const blob = await this.getBlob();
|
|
37
|
+
(0, _fileSaver.saveAs)(blob, filename);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @param {Window} win
|
|
42
|
+
* @returns {Promise}
|
|
43
|
+
*/
|
|
44
|
+
async open(win = null) {
|
|
45
|
+
if (!win) {
|
|
46
|
+
win = openWindow();
|
|
47
|
+
}
|
|
48
|
+
const blob = await this.getBlob();
|
|
49
|
+
try {
|
|
50
|
+
let urlCreator = window.URL || window.webkitURL;
|
|
51
|
+
let pdfUrl = urlCreator.createObjectURL(blob);
|
|
52
|
+
win.location.href = pdfUrl;
|
|
53
|
+
|
|
54
|
+
/* temporarily disabled
|
|
55
|
+
if (win === window) {
|
|
56
|
+
return;
|
|
57
|
+
} else {
|
|
58
|
+
setTimeout(() => {
|
|
59
|
+
if (win.window === null) { // is closed by AdBlock
|
|
60
|
+
window.location.href = pdfUrl; // open in actual window
|
|
61
|
+
}
|
|
62
|
+
return;
|
|
63
|
+
}, 500);
|
|
64
|
+
}
|
|
65
|
+
*/
|
|
66
|
+
} catch (e) {
|
|
67
|
+
win.close();
|
|
68
|
+
throw e;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @param {Window} win
|
|
74
|
+
* @returns {Promise}
|
|
75
|
+
*/
|
|
76
|
+
async print(win = null) {
|
|
77
|
+
const stream = await this.getStream();
|
|
78
|
+
stream.setOpenActionAsPrint();
|
|
79
|
+
await this.open(win);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
var _default = exports.default = OutputDocumentBrowser;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var fs = require('fs');
|
|
4
|
+
var fontContainer = {
|
|
5
|
+
vfs: {
|
|
6
|
+
'Roboto-Regular.ttf': {
|
|
7
|
+
data: fs.readFileSync(__dirname + '/../../../fonts/Roboto/Roboto-Regular.ttf', 'base64'),
|
|
8
|
+
encoding: 'base64'
|
|
9
|
+
},
|
|
10
|
+
'Roboto-Medium.ttf': {
|
|
11
|
+
data: fs.readFileSync(__dirname + '/../../../fonts/Roboto/Roboto-Medium.ttf', 'base64'),
|
|
12
|
+
encoding: 'base64'
|
|
13
|
+
},
|
|
14
|
+
'Roboto-Italic.ttf': {
|
|
15
|
+
data: fs.readFileSync(__dirname + '/../../../fonts/Roboto/Roboto-Italic.ttf', 'base64'),
|
|
16
|
+
encoding: 'base64'
|
|
17
|
+
},
|
|
18
|
+
'Roboto-MediumItalic.ttf': {
|
|
19
|
+
data: fs.readFileSync(__dirname + '/../../../fonts/Roboto/Roboto-MediumItalic.ttf', 'base64'),
|
|
20
|
+
encoding: 'base64'
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
fonts: {
|
|
24
|
+
Roboto: {
|
|
25
|
+
normal: 'Roboto-Regular.ttf',
|
|
26
|
+
bold: 'Roboto-Medium.ttf',
|
|
27
|
+
italics: 'Roboto-Italic.ttf',
|
|
28
|
+
bolditalics: 'Roboto-MediumItalic.ttf'
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
var _global = typeof window === 'object' ? window : typeof global === 'object' ? global : typeof self === 'object' ? self : void 0;
|
|
33
|
+
if (typeof _global.pdfMake !== 'undefined' && typeof _global.pdfMake.addFontContainer !== 'undefined') {
|
|
34
|
+
_global.pdfMake.addFontContainer(fontContainer);
|
|
35
|
+
}
|
|
36
|
+
if (typeof module !== 'undefined') {
|
|
37
|
+
module.exports = fontContainer;
|
|
38
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = void 0;
|
|
5
|
+
var _THSarabunNew = _interopRequireDefault(require("../../../fonts/THSarabunNew/THSarabunNew.ttf"));
|
|
6
|
+
var _THSarabunNewBold = _interopRequireDefault(require("../../../fonts/THSarabunNew/THSarabunNew-Bold.ttf"));
|
|
7
|
+
var _THSarabunNewItalic = _interopRequireDefault(require("../../../fonts/THSarabunNew/THSarabunNew-Italic.ttf"));
|
|
8
|
+
var _THSarabunNewBoldItalic = _interopRequireDefault(require("../../../fonts/THSarabunNew/THSarabunNew-BoldItalic.ttf"));
|
|
9
|
+
var _THSarabunIT = _interopRequireDefault(require("../../../fonts/THSarabunIT9/THSarabunIT9.ttf"));
|
|
10
|
+
var _THSarabunIT9Bold = _interopRequireDefault(require("../../../fonts/THSarabunIT9/THSarabunIT9-Bold.ttf"));
|
|
11
|
+
var _THSarabunIT9Italic = _interopRequireDefault(require("../../../fonts/THSarabunIT9/THSarabunIT9-Italic.ttf"));
|
|
12
|
+
var _THSarabunIT9BoldItalic = _interopRequireDefault(require("../../../fonts/THSarabunIT9/THSarabunIT9-BoldItalic.ttf"));
|
|
13
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
+
// w-pdfmaker: bundled Thai fonts for the browser build, inlined by webpack (asset/inline data URLs).
|
|
15
|
+
|
|
16
|
+
const base64 = dataUrl => dataUrl.slice(dataUrl.indexOf(',') + 1);
|
|
17
|
+
|
|
18
|
+
// keys match thaiFonts('') in ../../thai.js
|
|
19
|
+
var _default = exports.default = {
|
|
20
|
+
'THSarabunNew/THSarabunNew.ttf': base64(_THSarabunNew.default),
|
|
21
|
+
'THSarabunNew/THSarabunNew-Bold.ttf': base64(_THSarabunNewBold.default),
|
|
22
|
+
'THSarabunNew/THSarabunNew-Italic.ttf': base64(_THSarabunNewItalic.default),
|
|
23
|
+
'THSarabunNew/THSarabunNew-BoldItalic.ttf': base64(_THSarabunNewBoldItalic.default),
|
|
24
|
+
'THSarabunIT9/THSarabunIT9.ttf': base64(_THSarabunIT.default),
|
|
25
|
+
'THSarabunIT9/THSarabunIT9-Bold.ttf': base64(_THSarabunIT9Bold.default),
|
|
26
|
+
'THSarabunIT9/THSarabunIT9-Italic.ttf': base64(_THSarabunIT9Italic.default),
|
|
27
|
+
'THSarabunIT9/THSarabunIT9-BoldItalic.ttf': base64(_THSarabunIT9BoldItalic.default)
|
|
28
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = void 0;
|
|
5
|
+
var _base = _interopRequireDefault(require("../base"));
|
|
6
|
+
var _OutputDocumentBrowser = _interopRequireDefault(require("./OutputDocumentBrowser"));
|
|
7
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
8
|
+
var _configurator = _interopRequireDefault(require("core-js/configurator"));
|
|
9
|
+
var _pdfkit = require("pdfkit");
|
|
10
|
+
var _thai = require("../thai");
|
|
11
|
+
var _thai2 = _interopRequireDefault(require("./fonts/thai"));
|
|
12
|
+
var _pageUrls = require("./pageUrls");
|
|
13
|
+
var _URLResolver = require("../URLResolver");
|
|
14
|
+
var _variableType = require("../helpers/variableType");
|
|
15
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
16
|
+
// core-js: Polyfills will be used only if natives completely unavailable.
|
|
17
|
+
(0, _configurator.default)({
|
|
18
|
+
useNative: ['Promise']
|
|
19
|
+
});
|
|
20
|
+
let defaultClientFonts = {
|
|
21
|
+
Roboto: {
|
|
22
|
+
normal: 'Roboto-Regular.ttf',
|
|
23
|
+
bold: 'Roboto-Medium.ttf',
|
|
24
|
+
italics: 'Roboto-Italic.ttf',
|
|
25
|
+
bolditalics: 'Roboto-MediumItalic.ttf'
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
class pdfmake extends _base.default {
|
|
29
|
+
constructor() {
|
|
30
|
+
super();
|
|
31
|
+
this.fonts = Object.assign({}, defaultClientFonts, (0, _thai.thaiFonts)(''));
|
|
32
|
+
this.addVirtualFileSystem(_thai2.default);
|
|
33
|
+
}
|
|
34
|
+
createPdf(docDefinition, options) {
|
|
35
|
+
if ((0, _variableType.isObject)(docDefinition)) {
|
|
36
|
+
try {
|
|
37
|
+
docDefinition = (0, _pageUrls.withPageUrls)(docDefinition);
|
|
38
|
+
} catch (error) {
|
|
39
|
+
return this._transformToDocument(Promise.reject(error));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return super.createPdf(docDefinition, options);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* w-pdfmaker: reads a file passed by path to merge() / stamp(): from the virtual file system, else downloaded
|
|
47
|
+
* relative to the page.
|
|
48
|
+
*
|
|
49
|
+
* @param {string} path
|
|
50
|
+
* @returns {Promise<Uint8Array>}
|
|
51
|
+
*/
|
|
52
|
+
async _readFile(path) {
|
|
53
|
+
if (_fs.default.existsSync(path)) {
|
|
54
|
+
return _fs.default.readFileSync(path);
|
|
55
|
+
}
|
|
56
|
+
const response = await (0, _URLResolver.fetchUrl)((0, _pageUrls.pageUrl)(path), {}, this.urlAccessPolicy);
|
|
57
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
58
|
+
}
|
|
59
|
+
addFontContainer(fontContainer) {
|
|
60
|
+
if (fontContainer.standardFonts) {
|
|
61
|
+
(0, _pdfkit.registerStdFonts)(...fontContainer.standardFonts);
|
|
62
|
+
}
|
|
63
|
+
if (fontContainer.vfs) {
|
|
64
|
+
this.addVirtualFileSystem(fontContainer.vfs);
|
|
65
|
+
}
|
|
66
|
+
this.addFonts(fontContainer.fonts);
|
|
67
|
+
}
|
|
68
|
+
addVirtualFileSystem(vfs) {
|
|
69
|
+
for (let key in vfs) {
|
|
70
|
+
if (vfs.hasOwnProperty(key)) {
|
|
71
|
+
let data;
|
|
72
|
+
let encoding;
|
|
73
|
+
if (typeof vfs[key] === 'object') {
|
|
74
|
+
data = vfs[key].data;
|
|
75
|
+
encoding = vfs[key].encoding || 'base64';
|
|
76
|
+
} else {
|
|
77
|
+
data = vfs[key];
|
|
78
|
+
encoding = 'base64';
|
|
79
|
+
}
|
|
80
|
+
_fs.default.writeFileSync(key, data, encoding);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
_transformToDocument(doc) {
|
|
85
|
+
return new _OutputDocumentBrowser.default(doc);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
var _default = exports.default = new pdfmake();
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.withPageUrls = exports.pageUrl = void 0;
|
|
5
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
6
|
+
var _variableType = require("../helpers/variableType");
|
|
7
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
|
+
// w-pdfmaker: in the browser, a path (an image, an svg file, a PDF for merge/stamp) is a URL relative to the page.
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @param {string} path
|
|
12
|
+
* @returns {string} absolute http(s) URL
|
|
13
|
+
*/
|
|
14
|
+
const pageUrl = path => {
|
|
15
|
+
let url;
|
|
16
|
+
try {
|
|
17
|
+
url = new URL(path, globalThis.document?.baseURI ?? globalThis.location?.href);
|
|
18
|
+
} catch {
|
|
19
|
+
url = undefined;
|
|
20
|
+
}
|
|
21
|
+
if (!url || !/^https?:$/.test(url.protocol)) {
|
|
22
|
+
throw new Error(`Cannot load '${path}': in the browser a path is a URL on the web server of the page, so the page must be served over http(s). Use a data URL, binary data or addVirtualFileSystem() instead.`);
|
|
23
|
+
}
|
|
24
|
+
return url.href;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// Not empty (a missing image, see imageFallback.js), not data, not an absolute http(s) URL (downloaded as before),
|
|
28
|
+
// not SVG content and not a file in the virtual file system.
|
|
29
|
+
exports.pageUrl = pageUrl;
|
|
30
|
+
const isPath = value => (0, _variableType.isString)(value) && value.trim() !== '' && !/^(data|https?):/i.test(value) && !value.trim().startsWith('<') && !_fs.default.existsSync(value);
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Turns paths of images and svg files into URLs of the images dictionary, which are downloaded before layout.
|
|
34
|
+
* Content created by header/footer/background functions is not seen here; its paths must be in the images dictionary.
|
|
35
|
+
*
|
|
36
|
+
* @param {object} docDefinition
|
|
37
|
+
* @returns {object} docDefinition with a new images dictionary
|
|
38
|
+
*/
|
|
39
|
+
const withPageUrls = docDefinition => {
|
|
40
|
+
const images = {
|
|
41
|
+
...docDefinition.images
|
|
42
|
+
};
|
|
43
|
+
for (const [name, source] of Object.entries(images)) {
|
|
44
|
+
if (isPath(source)) {
|
|
45
|
+
images[name] = pageUrl(source);
|
|
46
|
+
} else if (source && typeof source === 'object' && isPath(source.url)) {
|
|
47
|
+
images[name] = {
|
|
48
|
+
...source,
|
|
49
|
+
url: pageUrl(source.url)
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const visited = new Set();
|
|
54
|
+
const visit = node => {
|
|
55
|
+
if (!node || typeof node !== 'object' || visited.has(node)) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
visited.add(node);
|
|
59
|
+
if (Array.isArray(node)) {
|
|
60
|
+
node.forEach(visit);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (Object.getPrototypeOf(node) !== Object.prototype) {
|
|
64
|
+
return; // binary data, DOM elements
|
|
65
|
+
}
|
|
66
|
+
for (const value of [node.image, node.svg]) {
|
|
67
|
+
if (isPath(value) && !Object.prototype.hasOwnProperty.call(images, value)) {
|
|
68
|
+
images[value] = pageUrl(value);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
Object.values(node).forEach(visit);
|
|
72
|
+
};
|
|
73
|
+
[docDefinition.content, docDefinition.header, docDefinition.footer, docDefinition.background].forEach(visit);
|
|
74
|
+
return {
|
|
75
|
+
...docDefinition,
|
|
76
|
+
images
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
exports.withPageUrls = withPageUrls;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var fontContainer = {
|
|
4
|
+
standardFonts: [require('pdfkit/standard-fonts/Courier'), require('pdfkit/standard-fonts/CourierBold'), require('pdfkit/standard-fonts/CourierOblique'), require('pdfkit/standard-fonts/CourierBoldOblique')],
|
|
5
|
+
fonts: {
|
|
6
|
+
Courier: {
|
|
7
|
+
normal: 'Courier',
|
|
8
|
+
bold: 'Courier-Bold',
|
|
9
|
+
italics: 'Courier-Oblique',
|
|
10
|
+
bolditalics: 'Courier-BoldOblique'
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
var _global = typeof window === 'object' ? window : typeof global === 'object' ? global : typeof self === 'object' ? self : void 0;
|
|
15
|
+
if (typeof _global.pdfMake !== 'undefined' && typeof _global.pdfMake.addFontContainer !== 'undefined') {
|
|
16
|
+
_global.pdfMake.addFontContainer(fontContainer);
|
|
17
|
+
}
|
|
18
|
+
if (typeof module !== 'undefined') {
|
|
19
|
+
module.exports = fontContainer;
|
|
20
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var fontContainer = {
|
|
4
|
+
standardFonts: [require('pdfkit/standard-fonts/Helvetica'), require('pdfkit/standard-fonts/HelveticaBold'), require('pdfkit/standard-fonts/HelveticaOblique'), require('pdfkit/standard-fonts/HelveticaBoldOblique')],
|
|
5
|
+
fonts: {
|
|
6
|
+
Helvetica: {
|
|
7
|
+
normal: 'Helvetica',
|
|
8
|
+
bold: 'Helvetica-Bold',
|
|
9
|
+
italics: 'Helvetica-Oblique',
|
|
10
|
+
bolditalics: 'Helvetica-BoldOblique'
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
var _global = typeof window === 'object' ? window : typeof global === 'object' ? global : typeof self === 'object' ? self : void 0;
|
|
15
|
+
if (typeof _global.pdfMake !== 'undefined' && typeof _global.pdfMake.addFontContainer !== 'undefined') {
|
|
16
|
+
_global.pdfMake.addFontContainer(fontContainer);
|
|
17
|
+
}
|
|
18
|
+
if (typeof module !== 'undefined') {
|
|
19
|
+
module.exports = fontContainer;
|
|
20
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var fontContainer = {
|
|
4
|
+
standardFonts: [require('pdfkit/standard-fonts/Symbol')],
|
|
5
|
+
fonts: {
|
|
6
|
+
Symbol: {
|
|
7
|
+
normal: 'Symbol'
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
var _global = typeof window === 'object' ? window : typeof global === 'object' ? global : typeof self === 'object' ? self : void 0;
|
|
12
|
+
if (typeof _global.pdfMake !== 'undefined' && typeof _global.pdfMake.addFontContainer !== 'undefined') {
|
|
13
|
+
_global.pdfMake.addFontContainer(fontContainer);
|
|
14
|
+
}
|
|
15
|
+
if (typeof module !== 'undefined') {
|
|
16
|
+
module.exports = fontContainer;
|
|
17
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var fontContainer = {
|
|
4
|
+
standardFonts: [require('pdfkit/standard-fonts/TimesRoman'), require('pdfkit/standard-fonts/TimesBold'), require('pdfkit/standard-fonts/TimesItalic'), require('pdfkit/standard-fonts/TimesBoldItalic')],
|
|
5
|
+
fonts: {
|
|
6
|
+
Times: {
|
|
7
|
+
normal: 'Times-Roman',
|
|
8
|
+
bold: 'Times-Bold',
|
|
9
|
+
italics: 'Times-Italic',
|
|
10
|
+
bolditalics: 'Times-BoldItalic'
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
var _global = typeof window === 'object' ? window : typeof global === 'object' ? global : typeof self === 'object' ? self : void 0;
|
|
15
|
+
if (typeof _global.pdfMake !== 'undefined' && typeof _global.pdfMake.addFontContainer !== 'undefined') {
|
|
16
|
+
_global.pdfMake.addFontContainer(fontContainer);
|
|
17
|
+
}
|
|
18
|
+
if (typeof module !== 'undefined') {
|
|
19
|
+
module.exports = fontContainer;
|
|
20
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var fontContainer = {
|
|
4
|
+
standardFonts: [require('pdfkit/standard-fonts/ZapfDingbats')],
|
|
5
|
+
fonts: {
|
|
6
|
+
ZapfDingbats: {
|
|
7
|
+
normal: 'ZapfDingbats'
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
var _global = typeof window === 'object' ? window : typeof global === 'object' ? global : typeof self === 'object' ? self : void 0;
|
|
12
|
+
if (typeof _global.pdfMake !== 'undefined' && typeof _global.pdfMake.addFontContainer !== 'undefined') {
|
|
13
|
+
_global.pdfMake.addFontContainer(fontContainer);
|
|
14
|
+
}
|
|
15
|
+
if (typeof module !== 'undefined') {
|
|
16
|
+
module.exports = fontContainer;
|
|
17
|
+
}
|