@wirabyte/w-pdfmaker 0.0.0-stage → 1.0.1

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