docx-make-pdf 0.0.2 → 0.0.3

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/README.MD CHANGED
@@ -1,97 +1,234 @@
1
1
  # docx-make-pdf
2
2
 
3
- 在后端(nodeJs环境)将docx文档转换为pdf。搭配docx-template可以实现生成订单。
3
+ [中文](#中文) | [English](#english)
4
4
 
5
- **步骤原理:**
5
+ ---
6
+
7
+ ## 中文
6
8
 
7
- 1. 通过[docx-preview](https://github.com/VolodymyrBaydalka/docxjs)的node修改版[docx-preview-node](https://github.com/ifeda/docx-preview-node)先转换为html
9
+ 纯 JavaScript 的在后端(Node.js 环境)将 docx 文档转换为 PDF。搭配 docx-template 可以实现订单生成。类似 [reamkit](https://www.npmjs.com/package/reamkit),更强的是不丢图片和单元格边框。
10
+ 如果 docx 文档内容较为复杂或者对生成的 PDF 一致性要求比较高、且有条件安装 LibreOffice 的,还是强烈建议使用 [docx-convert-pdf](https://github.com/ifeda/docx-convert-pdf)。
8
11
 
9
- 2. 再通过[html-to-pdfmake](https://github.com/Aymkdn/html-to-pdfmake)(基于源码修改)转换为pdfmake的docDefinition
12
+ **步骤原理:**
10
13
 
11
- 3. 然后通过[pdfmake](https://www.npmjs.com/package/pdfmake)输出为pdf文件
14
+ 1. 通过 [docx-preview](https://github.com/VolodymyrBaydalka/docxjs) 的 Node 修改版 [docx-preview-node](https://github.com/ifeda/docx-preview-node) 先转换为 HTML
15
+ 2. 再通过 [html-to-pdfmake](https://github.com/Aymkdn/html-to-pdfmake)(基于源码修改)转换为 pdfmake 的 docDefinition
16
+ 3. 然后通过 [pdfmake](https://www.npmjs.com/package/pdfmake) 输出为 PDF 文件
12
17
 
13
18
  **优点:**
14
19
 
15
- 1. 不需要操作系统安装依赖,纯js代码
20
+ 1. 不需要操作系统安装依赖,纯 JS 代码
21
+ 2. 支持输出 Buffer,方便后续通过 Node-SignPDF 等模块加数字签名
22
+ 3. 支持多页输出,支持识别 Word 分页符
23
+ 4. 异步模式 Promise
24
+ 5. TypeScript 友好
25
+
26
+ **缺点:**
16
27
 
17
- 2. 支持输出buffer方便后续通过Node-SignPDF等模块加数字签名
28
+ 1. 不支持 Word 文件既包含纵向页面也包含横向页面
29
+ 2. 不支持 Word 文本框、图表和绝对定位的图片等
30
+ 3. 宽度(如表格)适应不是很精确,无法精确地水平居中(所以尽量不要使用带边框的表格)
31
+ 4. 不能使用系统自带字体,必须自己加工 vfs 字体文件
32
+ 5. 集成了思源宋体,所以包比较大
18
33
 
19
- 3. 支持多页输出,支持识别word分页符
34
+ ### 安装 (Installation)
20
35
 
21
- 4. 异步模式Promise
36
+ `npm install -S docx-make-pdf`
22
37
 
23
- 5. Typescript友好
38
+ ### 使用 (Usage)
24
39
 
25
- **缺点:**
40
+ ```typescript
41
+ import docx2pdf from "docx-make-pdf"
42
+ docx2pdf({
43
+ docxFile:string, // docx file path, absolute path
44
+ docxBuffer:Buffer, // docx file content
45
+ },{
46
+ pageSize?: PageSize | undefined; // page size, default A4
47
+ pageOrientation?: "portrait" | "landscape"; // page orientation, default portrait
48
+ pageMargin?: pageMargin | undefined; // page margin, default 1.27cm (36pt)
49
+ version?: PDFVersion | undefined; // PDF version, default 1.7
50
+ watermark?: string | Watermark | undefined; // page watermark
51
+ language?: string | undefined; // page language, default zh-cn
52
+ vfs?: { [filename: string]: string }; // custom font data (load it yourself via require), note: filename here corresponds to the filename of normal/bold/italics/bolditalics in fonts
53
+ fonts?: TFontDictionary; // custom font definition, refer to build-vfs.js
54
+ defaultFont?: string; // default font name, default SourceHanSerifCN (Source Han Serif)
55
+ }):{
56
+ toFile: (filename: string) => Promise<string>; // write to file
57
+ toBuffer: () => Promise<Buffer>; // get generated PDF buffer
58
+ toStream: () => Promise<NodeJS.ReadableStream>; // custom pipe output
59
+ }
60
+ ```
26
61
 
27
- 1. 不支持word文件既包含纵向页面也包含横向页面
62
+ ### 字体的制作 (Font Customization)
28
63
 
29
- 2. 不支持word文本框、图表
64
+ 由于字体涉及版权问题,pdfmake 没有内置字体,也不会读取计算机/服务器上已安装的字体,因此需要您自行制作已获得版权的字体数据并加载。
30
65
 
31
- 3. 宽度(如表格)适应不是很精确,无法精确地水平居中(所以尽量不要使用带边框的表格)
66
+ Because of font licensing issues, pdfmake does not include built-in fonts, nor does it read fonts installed on the computer/server. You need to prepare your own licensed font data and load it yourself.
32
67
 
33
- 4. 不能使用系统自带字体,必须自己加工vfs字体文件
68
+ docx-make-pdf 内置了开源免费商用的思源宋体。如果您要添加字体,必须先加工 vfs,然后定义字体名称和文件名的对应关系。
34
69
 
35
- 5. 集成了思源宋体,所以包比较大
70
+ docx-make-pdf comes with the open-source, free-for-commercial-use Source Han Serif font. To add custom fonts, you must first process the vfs and then define the mapping between font names and filenames.
71
+
72
+ 1. **加工 vfs (Processing vfs)**
73
+
74
+ 生成 pdfmake 所能识别的字体源数据,原理是将 TTF 字体通过 Base64 编码加工成 vfs。建议最好用 TTF 字体,OTF 和 TTC 字体经验证未成功。Java 压缩过的字体也有问题,会出现无法识别的字符(似乎是空格)。
75
+
76
+ Generate font source data recognized by pdfmake. The principle is to encode TTF fonts into vfs via Base64. It's recommended to use TTF fonts—OTF and TTC fonts were not successful in testing. Java-compressed fonts also have issues with unrecognizable characters (seems to be spaces).
77
+
78
+ `node build-vfs.js <path> [filename]`
79
+
80
+ 参数说明 (Parameters):
81
+
82
+ - path: 字体所在目录,必须放在一个目录中,不支持子目录 (font directory, must be in a single directory, subdirectories not supported)
83
+ - filename: 存储 vfs 数据的文件,默认是 `build/vfs_fonts.js` (file to store vfs data, default: `build/vfs_fonts.js`)
84
+
85
+ docx-make-pdf 的 package.json 中内置了脚本可以参考:`node build-vfs.js ./fonts ./src/vfs_fonts.js`
86
+
87
+ **加载使用 (Loading & Using):**
88
+
89
+ ```javascript
90
+ const vfs_fonts = require("./vfs_fonts.js")
91
+ docx2pdf({docxBuffer},{vfs:vfs_fonts})
92
+ ```
93
+
94
+ 2. **定义字体名称和文件名对应关系 (Defining Font Name & Filename Mapping)**
95
+
96
+ 要使用 vfs 还必须按照如下格式定义字体 (To use vfs, fonts must be defined in the following format):
97
+
98
+ ```typescript
99
+ fontFaceName:string {
100
+ "normal": filename:string,
101
+ "bold": filename:string,
102
+ "italics": filename:string,
103
+ "bolditalics": filename:string
104
+ }
105
+ ```
106
+
107
+ 注意:必须定义 normal、bold、italics、bolditalics 四种样式,否则 pdfmake 会报错。如果字体没有这些样式,可以引用其他样式字体文件名,例如:
108
+
109
+ Note: All four styles (normal, bold, italics, bolditalics) must be defined, otherwise pdfmake will throw an error. If the font doesn't have these styles, you can reference other style font filenames, for example:
110
+
111
+ ```javascript
112
+ "SourceHanSerifCN": {
113
+ "normal": "SourceHanSerifCN-Regular.ttf",
114
+ "bold": "SourceHanSerifCN-Regular.ttf",
115
+ "italics": "SourceHanSerifCN-Regular.ttf",
116
+ "bolditalics": "SourceHanSerifCN-Regular.ttf"
117
+ }
118
+ ```
36
119
 
37
- ## 安装
120
+ `SourceHanSerifCN` 就是字体名称,比如:"宋体"、"simsun"。
121
+
122
+ `SourceHanSerifCN` is the font name, e.g. "SimSun", "simsun".
123
+
124
+ `SourceHanSerifCN-Regular.ttf` 是字体文件名(不需要带路径),必须和第一步加工 vfs 时一致(大小写敏感)。
125
+
126
+ `SourceHanSerifCN-Regular.ttf` is the font filename (no path needed), which must match the name used in the vfs processing step (case-sensitive).
127
+
128
+ **加载使用 (Loading & Using):**
129
+
130
+ ```typescript
131
+ docx2pdf({docxBuffer},{fonts:{
132
+ fontFaceName:string {
133
+ "normal": filename:string,
134
+ "bold": filename:string,
135
+ "italics": filename:string,
136
+ "bolditalics": filename:string
137
+ }
138
+ }})
139
+ ```
140
+
141
+ 提示:即使自定义了 vfs 和 fonts,也不会覆盖 docx2pdf 内置的 "SourceHanSerifCN" 和 pdfmake 内置的 "Roboto"(没有 Roboto 会报错)。
142
+
143
+ Tip: Even if you customize vfs and fonts, it will not override the built-in "SourceHanSerifCN" in docx2pdf and "Roboto" in pdfmake (pdfmake will error without Roboto).
144
+
145
+ ---
146
+
147
+ ## English
148
+
149
+ A pure JavaScript library for converting DOCX documents to PDF in the backend (Node.js environment). Combined with docx-template, it can generate documents like invoices. Similar to [reamkit](https://www.npmjs.com/package/reamkit), but better at preserving images and cell borders.
150
+
151
+ If the DOCX document content is complex or requires high PDF consistency, and you have the ability to install LibreOffice, it is strongly recommended to use [docx-convert-pdf](https://github.com/ifeda/docx-convert-pdf) instead.
152
+
153
+ **How it works:**
154
+
155
+ 1. Converts DOCX to HTML via [docx-preview-node](https://github.com/ifeda/docx-preview-node), a Node.js fork of [docx-preview](https://github.com/VolodymyrBaydalka/docxjs)
156
+ 2. Converts HTML to pdfmake's docDefinition via [html-to-pdfmake](https://github.com/Aymkdn/html-to-pdfmake) (modified from source)
157
+ 3. Outputs PDF file via [pdfmake](https://www.npmjs.com/package/pdfmake)
158
+
159
+ **Pros:**
160
+
161
+ 1. No OS-level dependencies required, pure JS code
162
+ 2. Supports Buffer output for easy digital signing with modules like Node-SignPDF
163
+ 3. Supports multi-page output and Word page breaks
164
+ 4. Async mode with Promises
165
+ 5. TypeScript friendly
166
+
167
+ **Cons:**
168
+
169
+ 1. Does not support Word documents with mixed portrait and landscape pages
170
+ 2. Does not support Word text boxes, charts, or absolutely positioned images
171
+ 3. Width adaptation (e.g., tables) is not very precise; cannot center horizontally with precision (avoid using bordered tables)
172
+ 4. Cannot use system fonts; must process vfs font files yourself
173
+ 5. Bundles Source Han Serif font, resulting in a large package size
174
+
175
+ ### Installation
38
176
 
39
177
  `npm install -S docx-make-pdf`
40
178
 
41
- ## 使用
179
+ ### Usage
42
180
 
43
181
  ```typescript
44
182
  import docx2pdf from "docx-make-pdf"
45
183
  docx2pdf({
46
- docxFile:string, //docx文件路径,绝对路径
47
- docxBuffer:Buffer, //docx文件内容
184
+ docxFile:string, // docx file path, absolute path
185
+ docxBuffer:Buffer, // docx file content
48
186
  },{
49
- pageSize?: PageSize | undefined; //页面大小,默认A4
50
- pageOrientation?: "portrait" | "landscape"; // 页面方向,默认纵向 portrait
51
- pageMargin?: pageMargin | undefined; // 页边距,默认1.27厘米(36pt)
52
- version?: PDFVersion | undefined; // pdf版本,默认1.7
53
- watermark?: string | Watermark | undefined; // 页面水印
54
- language?: string | undefined; //页面语言,默认zh-cn
55
- vfs?: { [filename: string]: string }; // 自定义字体数据(如果设置要自己require加载哦),注意这里的filename是fonts中normalbolditalicsbolditalics对应的filename
56
- fonts?: TFontDictionary; //自定义字体定义,参考build-vfs.js
57
- defaultFont?: string; // 默认字体名称,默认SourceHanSerifCN (思源宋体)
187
+ pageSize?: PageSize | undefined; // page size, default A4
188
+ pageOrientation?: "portrait" | "landscape"; // page orientation, default portrait
189
+ pageMargin?: pageMargin | undefined; // page margin, default 1.27cm (36pt)
190
+ version?: PDFVersion | undefined; // PDF version, default 1.7
191
+ watermark?: string | Watermark | undefined; // page watermark
192
+ language?: string | undefined; // page language, default zh-cn
193
+ vfs?: { [filename: string]: string }; // custom font data (load it yourself via require), note: filename here corresponds to the filename of normal/bold/italics/bolditalics in fonts
194
+ fonts?: TFontDictionary; // custom font definition, refer to build-vfs.js
195
+ defaultFont?: string; // default font name, default SourceHanSerifCN (Source Han Serif)
58
196
  }):{
59
- toFile: (filename: string) => Promise<string>; //写入文件名
60
- toBuffer: () => Promise<Buffer>; // Buffer 生成的pdf文件内容数据
61
- toStream: () => Promise<NodeJS.ReadableStream>; // 可以自定义pipe输出
197
+ toFile: (filename: string) => Promise<string>; // write to file
198
+ toBuffer: () => Promise<Buffer>; // get generated PDF buffer
199
+ toStream: () => Promise<NodeJS.ReadableStream>; // custom pipe output
62
200
  }
63
201
  ```
64
202
 
65
- ## 字体的制作
203
+ ### Font Customization
66
204
 
67
- 因为字体面临版权问题,所以pdfmake没有内置字体,也没有读取计算机/服务器上已经安装的字体,所以需要您自己制作已经获取版权的字体数据并加载。
205
+ Due to font licensing issues, pdfmake does not include built-in fonts, nor does it read fonts installed on the computer/server. You need to prepare your own licensed font data and load it yourself.
68
206
 
69
- docx-make-pdf内置了开源免费商用的思源宋体,如果您要添加字体,必须先加工vfs,然后定义字体名称和文件名对应关系。因为pdfmake说明较少,很多人容易糊涂,所以这里详细说明一下:
207
+ docx-make-pdf comes with the open-source, free-for-commercial-use Source Han Serif font. To add custom fonts, you must first process the vfs and then define the mapping between font names and filenames.
70
208
 
71
- 1. **加工vfs**
209
+ 1. **Processing vfs**
72
210
 
73
- 生成pdfmake所能识别的字体源数据,原理是将ttf字体通过base64编码加工成vfs;建议最好用ttf字体,otf字体和ttc字体我试验没成功;java压缩过的字体也有些问题,会出现无法识别的字符(似乎是空格);
211
+ Generate font source data recognized by pdfmake. The principle is to encode TTF fonts into vfs via Base64. It's recommended to use TTF fonts—OTF and TTC fonts were not successful in testing. Java-compressed fonts also have issues with unrecognizable characters (seems to be spaces).
74
212
 
75
213
  `node build-vfs.js <path> [filename]`
76
214
 
77
- 参数说明:
78
-
79
- - path: 字体所在目录,必须放在一个目录中,不支持子目录
215
+ Parameters:
80
216
 
81
- - filename: 存储vfs数据的文件,默认是build/vfs_fonts.js
217
+ - path: font directory, must be in a single directory, subdirectories not supported
218
+ - filename: file to store vfs data, default: `build/vfs_fonts.js`
82
219
 
83
- docx-make-pdfpackage.json中内置了script可以参考下: `node build-vfs.js ./fonts ./src/vfs_fonts.js`
220
+ docx-make-pdf has a built-in script in package.json: `node build-vfs.js ./fonts ./src/vfs_fonts.js`
84
221
 
85
- **加载使用:**
222
+ **Loading & Using:**
86
223
 
87
224
  ```javascript
88
225
  const vfs_fonts = require("./vfs_fonts.js")
89
226
  docx2pdf({docxBuffer},{vfs:vfs_fonts})
90
227
  ```
91
228
 
92
- 2. **定义字体名称和文件名对应关系**
229
+ 2. **Defining Font Name & Filename Mapping**
93
230
 
94
- 要使用vfs还必须按照如下格式定义字体:
231
+ To use vfs, fonts must be defined in the following format:
95
232
 
96
233
  ```typescript
97
234
  fontFaceName:string {
@@ -102,7 +239,7 @@ fontFaceName:string {
102
239
  }
103
240
  ```
104
241
 
105
- 注意:必须定义 normalbolditalicsbolditalics 四种样式,否则pdfmake会报错;如果字体没有这些样式,可以引用其他样式字体文件名,例如:
242
+ Note: All four styles (normal, bold, italics, bolditalics) must be defined, otherwise pdfmake will throw an error. If the font doesn't have these styles, you can reference other style font filenames, for example:
106
243
 
107
244
  ```javascript
108
245
  "SourceHanSerifCN": {
@@ -113,21 +250,21 @@ fontFaceName:string {
113
250
  }
114
251
  ```
115
252
 
116
- SourceHanSerifCN 就是字体名称,比如:"宋体" "simsun"
253
+ `SourceHanSerifCN` is the font name, e.g. "SimSun", "simsun".
117
254
 
118
- SourceHanSerifCN-Regular.ttf 这就是字体文件名(不需要带路径),必须和第一步加工vfs时一致(大小写敏感)
255
+ `SourceHanSerifCN-Regular.ttf` is the font filename (no path needed), which must match the name used in the vfs processing step (case-sensitive).
119
256
 
120
- **加载使用:**
257
+ **Loading & Using:**
121
258
 
122
259
  ```typescript
123
260
  docx2pdf({docxBuffer},{fonts:{
124
261
  fontFaceName:string {
125
-      "normal": filename:string,
126
-     "bold": filename:string,
127
-      "italics": filename:string,
128
-     "bolditalics": filename:string
129
-     }
262
+ "normal": filename:string,
263
+ "bold": filename:string,
264
+ "italics": filename:string,
265
+ "bolditalics": filename:string
266
+ }
130
267
  }})
131
268
  ```
132
269
 
133
- 提示:即时自定义了vfsfonts也不会覆盖docx2pdf内置的“SourceHanSerifCN"和pdfmake内置的"Roboto"(没有Roboto会报错)
270
+ Tip: Even if you customize vfs and fonts, it will not override the built-in "SourceHanSerifCN" in docx2pdf and "Roboto" in pdfmake (pdfmake will error without Roboto).
package/build-vfs.js CHANGED
File without changes
package/index.d.ts CHANGED
@@ -8,7 +8,7 @@ type pageMargin = {
8
8
  };
9
9
  type Input = {
10
10
  docxFile?: string;
11
- docxBuffer?: Buffer;
11
+ docxBuffer?: Buffer | Uint8Array;
12
12
  };
13
13
  type InputOptions = {
14
14
  pageSize?: PageSize | undefined;
@@ -25,8 +25,8 @@ type InputOptions = {
25
25
  };
26
26
 
27
27
  type Result = {
28
- toFile: (filename: string) => Promise<string>;
29
28
  toBuffer: () => Promise<Buffer>;
29
+ toFile: (filename: string) => Promise<string>;
30
30
  toStream: () => Promise<NodeJS.ReadableStream>;
31
31
  };
32
32
  declare function docx2pdf({ docxFile, docxBuffer }: Input, options?: InputOptions): Promise<Result>;
package/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var e=require("docx-preview-node"),t=require("jsdom"),a=require("pdfmake/build/pdfmake"),r=require("pdfmake/build/vfs_fonts");function i(e){return e&&e.__esModule?e:{default:e}}var o=i(a),s=i(r),n=Object.defineProperty,l=(e,t)=>n(e,"name",{value:t,configurable:!0}),c=(e=>"undefined"!=typeof require?require:"undefined"!=typeof Proxy?new Proxy(e,{get:(e,t)=>("undefined"!=typeof require?require:e)[t]}):e)(function(e){if("undefined"!=typeof require)return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')}),h={Roboto:{normal:"Roboto-Regular.ttf",bold:"Roboto-Medium.ttf",italics:"Roboto-Italic.ttf",bolditalics:"Roboto-MediumItalic.ttf"},SourceHanSerifCN:{normal:"SourceHanSerifCN-Regular.ttf",bold:"SourceHanSerifCN-Regular.ttf",italics:"SourceHanSerifCN-Regular.ttf",bolditalics:"SourceHanSerifCN-Regular.ttf"}},d={"4A0":[4767.87,6740.79],"2A0":[3370.39,4767.87],A0:[2383.94,3370.39],A1:[1683.78,2383.94],A2:[1190.55,1683.78],A3:[841.89,1190.55],A4:[595.28,841.89],A5:[419.53,595.28],A6:[297.64,419.53],A7:[209.76,297.64],A8:[147.4,209.76],A9:[104.88,147.4],A10:[73.7,104.88],B0:[2834.65,4008.19],B1:[2004.09,2834.65],B2:[1417.32,2004.09],B3:[1000.63,1417.32],B4:[708.66,1000.63],B5:[498.9,708.66],B6:[354.33,498.9],B7:[249.45,354.33],B8:[175.75,249.45],B9:[124.72,175.75],B10:[87.87,124.72],C0:[2599.37,3676.54],C1:[1836.85,2599.37],C2:[1298.27,1836.85],C3:[918.43,1298.27],C4:[649.13,918.43],C5:[459.21,649.13],C6:[323.15,459.21],C7:[229.61,323.15],C8:[161.57,229.61],C9:[113.39,161.57],C10:[79.37,113.39],RA0:[2437.8,3458.27],RA1:[1729.13,2437.8],RA2:[1218.9,1729.13],RA3:[864.57,1218.9],RA4:[609.45,864.57],SRA0:[2551.18,3628.35],SRA1:[1814.17,2551.18],SRA2:[1275.59,1814.17],SRA3:[907.09,1275.59],SRA4:[637.8,907.09],EXECUTIVE:[521.86,756],FOLIO:[612,936],LEGAL:[612,1008],LETTER:[612,792],TABLOID:[792,1224]},p=class e{static{l(this,"HtmlToPdfMake")}static convertToUnit(e){if(!isNaN(e)&&isFinite(parseFloat(e)))return parseFloat(e);var t=(e+"").trim().match(/^(-?\d*(\.\d+)?)(pt|px|r?em|cm|in)$/);if(!t)return!1;switch(e=t[1],t[3]){case"px":return.01*Math.round(.75292857248934*parseFloat(e)*100);case"em":case"rem":return 12*parseFloat(e);case"cm":return.01*Math.round(28.34646*parseFloat(e)*100);case"in":return 72*parseFloat(e);default:return parseFloat(e)}}static toCamelCase(e){return e.replace(/-([a-z])/g,function(e){return e[1].toUpperCase()})}static topRightBottomLeftToObject(e){var t=e.match(/#[0-9a-fA-F]{3,6}|\b(?:rgba?|hsla?)\([^)]*\)|\b[a-zA-Z]+\b/g)||[],a=t[0],r=t[1],i=t[2],o=t[3];switch(t.length){case 1:r=i=o=a;break;case 2:i=a,o=r;break;case 3:o=r}return{top:a,right:r,bottom:i,left:o}}static{this.hsl2rgb=l(function(e,t,a){var r=t*Math.min(a,1-a),i=l(function(t){var i=(t+e/30)%12;return Math.min(Math.floor(256*(a-r*Math.max(Math.min(i-3,9-i,1),-1))),255)},"f");return"rgb("+i(0)+","+i(8)+","+i(4)+")"},"hsl2rgb")}static parseColor(e){var t,a,r,i=1,o=new RegExp("^#([0-9a-f]{3}|[0-9a-f]{6})$","i"),s=/^rgba?\(\s*(\d+(\.\d+)?%?),\s*(\d+(\.\d+)?%?),\s*(\d+(\.\d+)?%?)(,\s*\d+(\.\d+)?)?\)$/,n=new RegExp("^hsl\\((\\d+(\\.\\d+)?%?),\\s*(\\d+(\\.\\d+)?%?),\\s*(\\d+(\\.\\d+)?%?)\\)$"),l=new RegExp("^[a-z]+$","i"),c=[];return o.test(e)?{color:e,opacity:i}:(n.test(e)&&(t=n.exec(e)?.slice(1),t&&(a=t[0].endsWith("%")?360*parseInt(t[0].slice(0,-1))/100:parseInt(t[0]),c.push(a),c.push(parseInt(t[2].slice(0,-1))/100),c.push(parseInt(t[4].slice(0,-1))/100),e=this.hsl2rgb(c[0],c[1],c[2]),c=[])),s.test(e)?(t=s.exec(e)?.slice(1),t&&t.filter(function(e,t){return t%2==0&&void 0!==e}).forEach(function(e,t){3===t?i=parseInt(e.slice(1)):((a=e.endsWith("%")?Math.round(255*parseInt(e.slice(0,-1))/100):parseInt(e))>255&&(a=255),r=(r="0"+a.toString(16)).slice(-2),c.push(r))}),{color:"#"+c.join(""),opacity:i}):(l.test(e)||console.error('Could not parse color "'+e+'"'),{color:e,opacity:i}))}static searchForStack(e){if(Array.isArray(e.text))for(var t=0;t<e.text.length;t++){if(e.text[t].stack||["SECTION","ARTICLE","DIV","P","SPAN","TABLE","SVG","UL","OL","IMG","H1","H2","H3","H4","H5","H6"].includes(e.text[t].nodeName))return!0;if(!0===this.searchForStack(e.text[t]))return!0}return!1}constructor(t){if("object"==typeof t.pageSize)this.pageSize=t.pageSize;else{var a=d[t?.pageSize||"A4"];this.pageSize={width:"portrait"==t?.pageOrientation?a[0]:a[1],height:"portrait"==t?.pageOrientation?a[1]:a[0]}}this.pageMargin=t?.pageMargin?{left:e.convertToUnit(t.pageMargin.left)||36,top:e.convertToUnit(t.pageMargin.top)||36,right:e.convertToUnit(t.pageMargin.right)||36,bottom:e.convertToUnit(t.pageMargin.bottom)||36}:{left:36,top:36,right:36,bottom:36},this.maxWidth=Math.round(this.pageSize.width-this.pageMargin.left-this.pageMargin.right-2),this.tableAutoSize=!t||"boolean"!=typeof t.tableAutoSize||t.tableAutoSize,this.imagesByReference=!(!t||"boolean"!=typeof t.imagesByReference)&&t.imagesByReference,this.removeExtraBlanks=!(!t||"boolean"!=typeof t.removeExtraBlanks)&&t.removeExtraBlanks,this.showHidden=!(!t||"boolean"!=typeof t.showHidden)&&t.showHidden,this.removeTagClasses=!(!t||"boolean"!=typeof t.removeTagClasses)&&t.removeTagClasses,this.ignoreStyles=t&&Array.isArray(t.ignoreStyles)?t.ignoreStyles:[],this.imagesByReferenceSuffix=Math.random().toString(36).slice(2,8),this.fontSizes=t&&Array.isArray(t.fontSizes)?t.fontSizes:[10,14,16,18,20,24,28],this.defaultStyles={b:{bold:!0},strong:{bold:!0},u:{decoration:"underline"},del:{decoration:"lineThrough"},s:{decoration:"lineThrough"},em:{italics:!0},i:{italics:!0},h1:{fontSize:24,bold:!0,marginBottom:5},h2:{fontSize:22,bold:!0,marginBottom:5},h3:{fontSize:20,bold:!0,marginBottom:5},h4:{fontSize:18,bold:!0,marginBottom:5},h5:{fontSize:16,bold:!0,marginBottom:5},h6:{fontSize:14,bold:!0,marginBottom:5},a:{color:"blue",decoration:"underline"},strike:{decoration:"lineThrough"},p:{margin:[0,5,0,5]},ul:{marginBottom:5,marginLeft:5},table:{marginBottom:5},th:{bold:!0,fillColor:"#EEEEEE"}},t.customTag&&(this.customTag=t.customTag),t.replaceText&&(this.replaceText=t.replaceText),t&&t.defaultStyles&&this.changeDefaultStyles(t.defaultStyles),this.imagesRef=[]}changeDefaultStyles(e){for(var t in e)if(this.defaultStyles.hasOwnProperty(t))if(e.hasOwnProperty(t)&&!e[t])delete this.defaultStyles[t];else for(var a in e[t])""===e[t][a]?delete this.defaultStyles[t][a]:this.defaultStyles[t][a]=e[t][a];else for(var r in this.defaultStyles[t]={},e[t])this.defaultStyles[t][r]=e[t][r]}getParentWidth(t){const a=t.parentNode;return a?a.style?.width||a.width?Math.min(e.convertToUnit(a.style?.width||a.width)||this.maxWidth,this.maxWidth):this.getParentWidth(a):this.maxWidth}convert(e){return"string"==typeof e?this._parserHTML(e):this._parserBody(e)}_parserHTML(e){this.removeExtraBlanks&&(e=e.replace(/(<\/?(div|p|h1|h2|h3|h4|h5|h6|ol|ul|li)([^>]+)?>)\s+(<\/?(div|p|h1|h2|h3|h4|h5|h6|ol|ul|li))/gi,"$1$4").replace(/(<\/?(div|p|h1|h2|h3|h4|h5|h6|ol|ul|li)([^>]+)?>)\s+(<\/?(div|p|h1|h2|h3|h4|h5|h6|ol|ul|li))/gi,"$1$4").replace(/(<td([^>]+)?>)\s+(<table)/gi,"$1$3").replace(/(<\/table>)\s+(<\/td>)/gi,"$1$2"));const a=new t.JSDOM("<html><body></body></html>").window.document;return a.body.innerHTML=e,this._parserBody(a.body)}_parserBody(e){var t=this.parseElement(e,[]);let a=t.stack||t.text;return"string"==typeof a&&(a={text:a}),this.imagesByReference&&(a={content:a,images:{}},this.imagesRef.forEach((e,t)=>{a.images["img_ref_"+this.imagesByReferenceSuffix+t]=e.startsWith("{")?JSON.parse(e):e})),a}parseElement(t,a){var r,i,o,s,n=t.nodeName.toUpperCase(),c=n.toLowerCase(),h={text:[]},d=this;if(["STYLE","SCRIPT","META","COLGROUP","COL"].indexOf(n)>-1)return"";switch(t.nodeType){case 3:if(t.textContent){r=t.textContent;var p=this.parseStyle(a[a.length-1],!0),u=a.findIndex(function(e){return"PRE"===e.nodeName})>-1;for(o=0;o<p.length;o++)if("preserveLeadingSpaces"===p[o].key){u=p[o].value;break}if(u||(r=r.replace(/\s*\n\s*/g," ")),"function"==typeof this.replaceText&&(r=this.replaceText(r,a)),["TABLE","THEAD","TBODY","TFOOT","TR","UL","OL"].indexOf(a[a.length-1].nodeName)>-1&&(r=r.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")),r)return h={text:r},h=this.applyStyle({ret:h,parents:a})}return"";case 1:if(!this.showHidden&&t.style.display&&"none"===t.style.display||t.style.visibility&&"hidden"===t.style.visibility)return;switch(null!==t.getAttribute("page")&&"1"!==t.getAttribute("page")&&(h.pageBreak="before"),h.nodeName=n,t.id&&(h.id=t.id),a.push(t),t.childNodes&&t.childNodes.length>0&&([].forEach.call(t.childNodes,e=>{var t=d.parseElement(e,a);t&&(Array.isArray(t.text)&&0===t.text.length&&(t.text=" "),h.text.push(t))}),e.searchForStack(h)?(h.stack=h.text.slice(0),delete h.text,h=this.applyStyle({ret:h,parents:[t]})):h=this.applyStyle({ret:h,parents:a})),a.pop(),n){case"DIV":"p"==t.parentNode.nodeName&&(h=this.applyStyle({ret:h,parents:a}));break;case"TABLE":var f;h.table={body:[]};var g=h.stack||h.text;if(Array.isArray(g)){f=0;var y=!1;if(g.forEach(function(e){var t=e.stack||e.text;Array.isArray(t)&&t.forEach(function(e){var t=e.stack||e.text;Array.isArray(t)&&(h.table.body[f]=[],t.forEach(function(e){if(h.table.body[f].push(e),e.colSpan>1)for(o=e.colSpan;--o>0;)h.table.body[f].push({text:" "});e.rowSpan>1&&(y=!0)}),f++)})}),y){var m=h.table.body[0];if(Array.isArray(m))for(var b=m.length,v=h.table.body.length,k=0;k<b;k++)for(var x=0;x<v;x++){var S=h.table.body[x];if(Array.isArray(S)){var A=S[k];if(A.rowSpan>1){for(var T,w=A.rowSpan,C=A.colSpan?A.colSpan:1,O=1;O<=w-1;O++)if(T=C,h.table.body[x+O])for(;T--;)h.table.body[x+O].splice(k,0,{text:""});else A.rowSpan--;x+=w-1}}}}}if(delete h.stack,delete h.text,h=this.applyStyle({ret:h,parents:a.concat([t])}),this.tableAutoSize){var E=[],B=[],R=[],L=[],M=t.getAttribute("width")||t.style.width,N=M.endsWith("%");N?(M=Math.round(this.getParentWidth(t)*parseFloat(M.replace(/[^\d\.]/g,""))*.01),console.log(this.maxWidth,M)):isNaN(M)&&(M=e.convertToUnit(M));for(var z=!1,F=-1,U=0;U<t.children.length;U++){z||F++,"COLGROUP"===t.children[U].nodeName.toUpperCase()&&(z=!0)}if(h.table.body.forEach(function(e,t){E.push([]),B.push([]),e.forEach(function(e,a){var r=void 0!==e.width?e.width:"auto";"*"===r&&(r="auto");var i=void 0!==e.height?e.height:"auto";"*"===i&&(i="auto"),"auto"!==r&&e.colSpan>1&&(isNaN(r)?r="auto":r/=e.colSpan),"auto"!==i&&e.rowSpan>1&&(isNaN(i)?i="auto":i/=e.rowSpan),E[t].push(r),B[t].push(i)})}),z){var H=t.children[F];[].forEach.call(H.childNodes,(a,r)=>{var i=a.getAttribute("width")||a.style.width;i.endsWith("%")?R[r]=.01*parseFloat(i.replace(/[^\d\.]/g,""))*this.getParentWidth(t):R[r]=e.convertToUnit(i)})}E.forEach(function(e){e.forEach(function(t,a){var r=typeof R[a];("undefined"===r||"auto"!==t&&"number"===r&&t>R[a]||"auto"!==t&&"auto"===R[a])&&(N&&(t="auto"===t?M/e.length:.01*t.toString().replace("%","")*M),R[a]=t)})}),B.forEach(function(e,t){e.forEach(function(e){var a=typeof L[t];("undefined"===a||"auto"!==e&&"number"===a&&e>L[t]||"auto"!==e&&"auto"===L[t])&&(L[t]=e)})}),R.length>0&&(h.table.widths=R.map(e=>.01*Math.round(100*(e-2*R.length)))),L.length>0&&(h.table.heights=L)}if(t.dataset&&t.dataset.pdfmake){i=t.dataset.pdfmake.replace(/'/g,'"');try{for(s in i=JSON.parse(i))"layout"===s?h.layout=i[s]:h.table[s]=i[s]}catch(e){console.error(e)}}else h.layout="html-table";break;case"TH":case"TD":t.getAttribute("rowspan")&&(h.rowSpan=1*t.getAttribute("rowspan")),t.getAttribute("colspan")&&(h.colSpan=1*t.getAttribute("colspan"));break;case"SVG":h={svg:t.outerHTML.replace(/\n(\s+)?/g,""),nodeName:"SVG"},this.removeTagClasses||(h.style=["html-svg"]);break;case"BR":h.text=[{text:"\n"}];break;case"SUB":case"SUP":h[n.toLowerCase()]={offset:"30%",fontSize:8};break;case"HR":var P={width:514,type:"line",margin:[0,12,0,12],thickness:.5,color:"#000000",left:0};if(t.dataset&&t.dataset.pdfmake){i=t.dataset.pdfmake.replace(/'/g,'"');try{for(s in i=JSON.parse(i))P[s]=i[s]}catch(e){console.error(e)}}h.margin=P.margin,h.canvas=[{type:P.type,x1:P.left,y1:0,x2:P.width,y2:0,lineWidth:P.thickness,lineColor:P.color}],delete h.text;break;case"OL":case"UL":switch(h[c]=(h.stack||h.text).slice(0),delete h.stack,delete h.text,h=this.applyStyle({ret:h,parents:a.concat([t])}),t.getAttribute("start")&&(h.start=1*t.getAttribute("start")),t.getAttribute("type")){case"A":h.type="upper-alpha";break;case"a":h.type="lower-alpha";break;case"I":h.type="upper-roman";break;case"i":h.type="lower-roman"}(h.listStyle||h.listStyleType)&&(h.type=h.listStyle||h.listStyleType);break;case"LI":h.stack&&!h.stack[h.stack.length-1].text&&(r=h.stack.slice(0,-1),h=[{text:r},h.stack[h.stack.length-1]]),Array.isArray(h)&&(h={stack:h});break;case"PRE":h.preserveLeadingSpaces=!0;break;case"IMG":if(h=this.applyStyle({ret:h,parents:a.concat([t])}),this.imagesByReference){var I=t.getAttribute("data-src")||t.getAttribute("src"),W=this.imagesRef.indexOf(I);W>-1?h.image="img_ref_"+this.imagesByReferenceSuffix+W:(h.image="img_ref_"+this.imagesByReferenceSuffix+this.imagesRef.length,this.imagesRef.push(I))}else h.image=t.getAttribute("src");delete h.stack,delete h.text;break;case"A":var $=l(function(e,t){return e=e||{text:""},Array.isArray(e.text)?(e.text=e.text.map(function(e){return $(e,t)}),e):Array.isArray(e.stack)?(e.stack=e.stack.map(function(e){return $(e,t)}),e):(0===t.indexOf("#")?e.linkToDestination=t.slice(1):e.link=t,e)},"setLink");t.getAttribute("href")&&(h=$(h,t.getAttribute("href")),Array.isArray(h.text)&&1===h.text.length&&(h=h.text[0]),h.nodeName="A");break;default:"DIV"===n&&t.dataset&&"columns"===t.dataset.pdfmakeType?h.stack&&(h.columns=h.stack,delete h.stack):"function"==typeof this.customTag&&(h=this.customTag.call(this,{element:t,parents:a,ret:h}))}if(Array.isArray(h.text)&&1===h.text.length&&h.text[0].text&&!h.text[0].nodeName&&(h.text=h.text[0].text),-1===["HR","TABLE"].indexOf(n)&&t.dataset&&t.dataset.pdfmake){i=t.dataset.pdfmake.replace(/'/g,'"');try{for(s in i=JSON.parse(i))h[s]=i[s]}catch(e){console.error(e)}}return h}}applyStyle(e){var t=[],a=e.parents.length-1,r=this;return e.parents.forEach(function(i,o){var s,n=i.nodeName.toLowerCase();if(!r.removeTagClasses){var l="html-"+n;"html-body"!==l&&-1===t.indexOf(l)&&t.unshift(l)}(i.getAttribute("class")||"").split(" ").forEach(function(e){e&&t.push(e)});var c=o!==a;if(r.defaultStyles[n])for(s in r.defaultStyles[n])r.defaultStyles[n].hasOwnProperty(s)&&(!c||c&&-1===s.indexOf("margin")&&-1===s.indexOf("border"))&&("decoration"===s?(Array.isArray(e.ret[s])||(e.ret[s]=[]),r.defaultStyles[n][s]&&-1===e.ret[s].indexOf(r.defaultStyles[n][s])&&e.ret[s].push(r.defaultStyles[n][s])):e.ret[s]=JSON.parse(JSON.stringify(r.defaultStyles[n][s])));"tr"===n&&(c=!1),(s=r.parseStyle(i,c)).forEach(function(t){if("decoration"===t.key)Array.isArray(e.ret[t.key])||(e.ret[t.key]=[]),e.ret[t.key].push(t.value);else if(["ul","ol"].includes(n)&&"alignment"===t.key);else if(e.ret.margin&&0===t.key.indexOf("margin"))switch(t.key){case"marginLeft":e.ret.margin[0]=t.value;break;case"marginTop":e.ret.margin[1]=t.value;break;case"marginRight":e.ret.margin[2]=t.value;break;case"marginBottom":e.ret.margin[3]=t.value}else["minHeight"].includes(t.key)||(e.ret[t.key]=t.value)})}),t.length>0&&(e.ret.style=t),e.ret}borderValueRearrange(e){try{var t=e.split(" ");if(3!==t.length)return e;var a="0px",r="none",i="transparent",o=["dotted","dashed","solid","double","groove","ridge","inset","outset","none","hidden","mix"];return t.forEach(function(e){e.match(/^\d/)?a=e:o.indexOf(e)>-1?r=e:i=e}),a+" "+r+" "+i}catch(t){return e}}parseStyle(t,a){var r=t.getAttribute("style")||"",i=[];r=r.replace(/!important/g,"").split(";");var o=t.getAttribute("width")||t.style.width,s=t.getAttribute("height")||t.style.height;o&&(o.endsWith("%")?o=this.getParentWidth(t)*parseFloat(o.replace(/[^\d\.]/g,""))*.01:isNaN(o)&&(o=e.convertToUnit(o)),r.unshift("width:"+o)),s&&r.unshift("height:"+e.convertToUnit(s+(isNaN(s)?"":"px")));var n=t.getAttribute("color");n&&i.push({key:"color",value:e.parseColor(n).color});var l=t.getAttribute("size");null!==l&&(l=Math.min(Math.max(1,parseInt(l)),7),i.push({key:"fontSize",value:Math.max(this.fontSizes[0],this.fontSizes[l-1])}));var c=r.map(function(e){return e.toLowerCase().split(":")}),h=[],d=t.nodeName.toUpperCase(),p=this;if(c.forEach(function(t){if(2===t.length){var r,o=t[0].trim().toLowerCase(),s=t[1].trim();if(-1===p.ignoreStyles.indexOf(o))switch(o){case"margin":{if(a)break;let t=s.split(" ");1===t.length?t=[t[0],t[0],t[0],t[0]]:2===t.length?t=[t[1],t[0]]:3===t.length?t=[t[1],t[0],t[1],t[2]]:4===t.length&&(t=[t[3],t[0],t[1],t[2]]),t.forEach(function(a,r){t[r]="auto"===a?"":e.convertToUnit(a)}),-1===t.indexOf(!1)&&i.push({key:o,value:s});break}case"line-height":s="string"==typeof s&&"%"===s.slice(-1)?parseFloat(s.slice(0,-1))/100:e.convertToUnit(s),i.push({key:"lineHeight",value:s});break;case"text-align":i.push({key:"alignment",value:s});break;case"font-weight":"bold"===s&&i.push({key:"bold",value:!0});break;case"text-decoration":s=e.toCamelCase(s),["underline","lineThrough","overline"].includes(s)&&i.push({key:"decoration",value:s});break;case"font-style":"italic"===s&&i.push({key:"italics",value:!0});break;case"font-family":i.push({key:"font",value:s.split(",")[0].replace(/"|^'|^\s*|\s*$|'$/g,"").replace(/^([a-z])/g,function(e){return e[0].toUpperCase()}).replace(/ ([a-z])/g,function(e){return e[1].toUpperCase()})});break;case"color":r=e.parseColor(s),i.push({key:"color",value:r.color}),r.opacity<1&&i.push({key:"opacity",value:r.opacity});break;case"background-color":r=e.parseColor(s),i.push({key:"TD"===d||"TH"===d?"fillColor":"background",value:r.color}),r.opacity<1&&i.push({key:"TD"===d||"TH"===d?"fillOpacity":"opacity",value:r.opacity});break;case"text-indent":i.push({key:"leadingIndent",value:e.convertToUnit(s)});break;case"white-space":"nowrap"===s?i.push({key:"noWrap",value:!0}):i.push({key:"preserveLeadingSpaces",value:"break-spaces"===s||"pre"===s.slice(0,3)});break;default:if(0===o.indexOf("border"))a||h.push({key:o,value:s});else{if(a||0===o.indexOf("margin-")||"width"===o||"height"===o)break;if("IMG"===d&&("width"===o||"height"===o)){i.push({key:o,value:e.convertToUnit(s)});break}if(0===o.indexOf("padding"))break;if(o.indexOf("-")>-1&&(o=e.toCamelCase(o)),s){var n=e.convertToUnit(s);if("fontSize"===o&&!1===n){if(!["xx-small","x-small","small","medium","large","x-large","xx-large","xxx-large"].includes(s))break;switch(s){case"xx-small":s=7.2;break;case"x-small":s=9;break;case"small":s=10.7;break;case"medium":s=12;break;case"large":s=14.4;break;case"x-large":s=18;break;case"xx-large":s=24;break;case"xxx-large":s=36}}if(0===o.indexOf("margin")&&"auto"===s)break;i.push({key:o,value:!1===n?s:n})}}}}}),h.length>0){var u=[],f=[];h.forEach(function(t){var a,r=-1;t.key.indexOf("-left")>-1?r=0:t.key.indexOf("-top")>-1?r=1:t.key.indexOf("-right")>-1?r=2:t.key.indexOf("-bottom")>-1&&(r=3);var i,o,s=t.key.split("-");if(1===s.length||2===s.length&&r>=0){if(t.value=p.borderValueRearrange(t.value),o=(i=t.value.split(" "))[0].replace(/(\d*)(\.\d+)?([^\d]+)/g,"$1$2 ").trim(),r>-1)u[r]=o>0;else for(a=0;a<4;a++)u[a]=o>0;if(i.length>2){var n=i.slice(2).join(" ");if(r>-1)f[r]=e.parseColor(n).color;else for(a=0;a<4;a++)f[a]=e.parseColor(n).color}}else r>=0&&"color"===s[2]?f[r]=e.parseColor(t.value).color:r>=0&&"width"===s[2]?u[r]=!/^0[a-z%]*$/.test(String(t.value)):"border-color"===t.key?(i=e.topRightBottomLeftToObject(t.value),f=[e.parseColor(i.left).color,e.parseColor(i.top).color,e.parseColor(i.right).color,e.parseColor(i.bottom).color]):"border-width"===t.key&&(i=e.topRightBottomLeftToObject(t.value),u=[!/^0[a-z%]*$/.test(i.left),!/^0[a-z%]*$/.test(i.top),!/^0[a-z%]*$/.test(i.right),!/^0[a-z%]*$/.test(i.bottom)])});for(var g=0;g<4;g++)u.length>0&&void 0===u[g]&&(u[g]=!0),f.length>0&&void 0===f[g]&&(f[g]="#000000");u.length>0&&i.push({key:"border",value:u}),f.length>0&&i.push({key:"borderColor",value:f})}return i}},u=c("path"),f=c("fs");async function g({docxFile:a,docxBuffer:r},i){if(!a||!f.existsSync(a))return Promise.reject(`Not found docx file:${a}`);if(r=f.readFileSync(a)){const a=new t.JSDOM("<!DOCTYPE html><html><body></body></html>",{pretendToBeVisual:!0}).window.document.body;await e.renderAsync(r,a,void 0,{inWrapper:!1,ignoreWidth:!0,ignoreHeight:!0,ignoreLastRenderedPageBreak:!0,renderHeaders:!1,renderFooters:!1,useBase64URL:!0,ignoreFonts:!0,renderFootnotes:!1,renderEndnotes:!1,renderComments:!1,renderAltChunks:!1,hideWrapperOnPrint:!0,breakPages:!0});const n=a.innerHTML.replace(/<\/?span[^>]*>/g,""),d=new p({pageSize:i?.pageSize,pageOrientation:i?.pageOrientation||"portrait",pageMargin:i?.pageMargin}).convert(n),g={version:i?.version||"1.7",language:i?.language||"zh-CN",pageSize:i?.pageSize||"A4",pageOrientation:i?.pageOrientation||"portrait",defaultStyle:{font:i?.defaultFont||"SourceHanSerifCN"},pageMargins:i?.pageMargin?[p.convertToUnit(i.pageMargin.left)||36,p.convertToUnit(i.pageMargin.top)||36,p.convertToUnit(i.pageMargin.right)||36,p.convertToUnit(i.pageMargin.bottom)||36]:[36,36,36,36],watermark:i?.watermark,content:d},y=i?.vfs||c("./vfs_fonts.js");o.default.vfs={...s.default,...y},o.default.fonts=i?.fonts||h;const m=o.default.createPdf(g),b={tableLayouts:{"html-table":{hLineWidth:l(()=>.5,"hLineWidth"),vLineWidth:l(()=>.5,"vLineWidth")}}};return{toBuffer:l(()=>new Promise((e,t)=>{try{m.getBuffer(t=>{e(t)},b)}catch(e){t(e)}}),"toBuffer"),toFile:l(e=>new Promise((t,a)=>{try{m.getBuffer(a=>{f.writeFileSync(u.resolve(e),a),t(u.resolve(e))},b)}catch(e){a(e)}}),"toFile"),toStream:l(()=>new Promise((e,t)=>{try{e(m.getStream(b))}catch(e){t(e)}}),"toStream")}}return Promise.reject("Either docx file path<docxFile> or buffer object<docxBuffer> must be provided.")}l(g,"docx2pdf");var y=g;module.exports=y;
1
+ "use strict";var e=require("path"),t=require("fs"),a=require("docx-preview-node"),r=require("jsdom"),i=require("pdfmake/build/pdfmake"),o=require("pdfmake/build/vfs_fonts");function s(e){return e&&e.__esModule?e:{default:e}}var n=s(e),l=s(t),c=s(i),h=s(o),d=Object.defineProperty,u=(e,t)=>d(e,"name",{value:t,configurable:!0}),p=(e=>"undefined"!=typeof require?require:"undefined"!=typeof Proxy?new Proxy(e,{get:(e,t)=>("undefined"!=typeof require?require:e)[t]}):e)(function(e){if("undefined"!=typeof require)return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')}),f={Roboto:{normal:"Roboto-Regular.ttf",bold:"Roboto-Medium.ttf",italics:"Roboto-Italic.ttf",bolditalics:"Roboto-MediumItalic.ttf"},SourceHanSerifCN:{normal:"SourceHanSerifCN-Regular.ttf",bold:"SourceHanSerifCN-Regular.ttf",italics:"SourceHanSerifCN-Regular.ttf",bolditalics:"SourceHanSerifCN-Regular.ttf"}},g={"4A0":[4767.87,6740.79],"2A0":[3370.39,4767.87],A0:[2383.94,3370.39],A1:[1683.78,2383.94],A2:[1190.55,1683.78],A3:[841.89,1190.55],A4:[595.28,841.89],A5:[419.53,595.28],A6:[297.64,419.53],A7:[209.76,297.64],A8:[147.4,209.76],A9:[104.88,147.4],A10:[73.7,104.88],B0:[2834.65,4008.19],B1:[2004.09,2834.65],B2:[1417.32,2004.09],B3:[1000.63,1417.32],B4:[708.66,1000.63],B5:[498.9,708.66],B6:[354.33,498.9],B7:[249.45,354.33],B8:[175.75,249.45],B9:[124.72,175.75],B10:[87.87,124.72],C0:[2599.37,3676.54],C1:[1836.85,2599.37],C2:[1298.27,1836.85],C3:[918.43,1298.27],C4:[649.13,918.43],C5:[459.21,649.13],C6:[323.15,459.21],C7:[229.61,323.15],C8:[161.57,229.61],C9:[113.39,161.57],C10:[79.37,113.39],RA0:[2437.8,3458.27],RA1:[1729.13,2437.8],RA2:[1218.9,1729.13],RA3:[864.57,1218.9],RA4:[609.45,864.57],SRA0:[2551.18,3628.35],SRA1:[1814.17,2551.18],SRA2:[1275.59,1814.17],SRA3:[907.09,1275.59],SRA4:[637.8,907.09],EXECUTIVE:[521.86,756],FOLIO:[612,936],LEGAL:[612,1008],LETTER:[612,792],TABLOID:[792,1224]},y=class e{static{u(this,"HtmlToPdfMake")}static convertToUnit(e){if(!isNaN(e)&&isFinite(parseFloat(e)))return parseFloat(e);var t=(e+"").trim().match(/^(-?\d*(\.\d+)?)(pt|px|r?em|cm|in)$/);if(!t)return!1;switch(e=t[1],t[3]){case"px":return.01*Math.round(.75292857248934*parseFloat(e)*100);case"em":case"rem":return 12*parseFloat(e);case"cm":return.01*Math.round(28.34646*parseFloat(e)*100);case"in":return 72*parseFloat(e);default:return parseFloat(e)}}static toCamelCase(e){return e.replace(/-([a-z])/g,function(e){return e[1].toUpperCase()})}static topRightBottomLeftToObject(e){var t=e.match(/#[0-9a-fA-F]{3,6}|\b(?:rgba?|hsla?)\([^)]*\)|\b[a-zA-Z]+\b/g)||[],a=t[0],r=t[1],i=t[2],o=t[3];switch(t.length){case 1:r=i=o=a;break;case 2:i=a,o=r;break;case 3:o=r}return{top:a,right:r,bottom:i,left:o}}static{this.hsl2rgb=u(function(e,t,a){var r=t*Math.min(a,1-a),i=u(function(t){var i=(t+e/30)%12;return Math.min(Math.floor(256*(a-r*Math.max(Math.min(i-3,9-i,1),-1))),255)},"f");return"rgb("+i(0)+","+i(8)+","+i(4)+")"},"hsl2rgb")}static parseColor(e){var t,a,r,i=1,o=new RegExp("^#([0-9a-f]{3}|[0-9a-f]{6})$","i"),s=/^rgba?\(\s*(\d+(\.\d+)?%?),\s*(\d+(\.\d+)?%?),\s*(\d+(\.\d+)?%?)(,\s*\d+(\.\d+)?)?\)$/,n=new RegExp("^hsl\\((\\d+(\\.\\d+)?%?),\\s*(\\d+(\\.\\d+)?%?),\\s*(\\d+(\\.\\d+)?%?)\\)$"),l=new RegExp("^[a-z]+$","i"),c=[];return o.test(e)?{color:e,opacity:i}:(n.test(e)&&(t=n.exec(e)?.slice(1),t&&(a=t[0].endsWith("%")?360*parseInt(t[0].slice(0,-1))/100:parseInt(t[0]),c.push(a),c.push(parseInt(t[2].slice(0,-1))/100),c.push(parseInt(t[4].slice(0,-1))/100),e=this.hsl2rgb(c[0],c[1],c[2]),c=[])),s.test(e)?(t=s.exec(e)?.slice(1),t&&t.filter(function(e,t){return t%2==0&&void 0!==e}).forEach(function(e,t){3===t?i=parseInt(e.slice(1)):((a=e.endsWith("%")?Math.round(255*parseInt(e.slice(0,-1))/100):parseInt(e))>255&&(a=255),r=(r="0"+a.toString(16)).slice(-2),c.push(r))}),{color:"#"+c.join(""),opacity:i}):(l.test(e)||console.error('Could not parse color "'+e+'"'),{color:e,opacity:i}))}static searchForStack(e){if(Array.isArray(e.text))for(var t=0;t<e.text.length;t++){if(e.text[t].stack||["SECTION","ARTICLE","DIV","P","SPAN","TABLE","SVG","UL","OL","IMG","H1","H2","H3","H4","H5","H6"].includes(e.text[t].nodeName))return!0;if(!0===this.searchForStack(e.text[t]))return!0}return!1}constructor(t){if("object"==typeof t.pageSize)this.pageSize=t.pageSize;else{var a=g[t?.pageSize||"A4"];this.pageSize={width:"portrait"==t?.pageOrientation?a[0]:a[1],height:"portrait"==t?.pageOrientation?a[1]:a[0]}}this.pageMargin=t?.pageMargin?{left:e.convertToUnit(t.pageMargin.left)||36,top:e.convertToUnit(t.pageMargin.top)||36,right:e.convertToUnit(t.pageMargin.right)||36,bottom:e.convertToUnit(t.pageMargin.bottom)||36}:{left:36,top:36,right:36,bottom:36},this.maxWidth=Math.round(this.pageSize.width-this.pageMargin.left-this.pageMargin.right-2),this.tableAutoSize=!t||"boolean"!=typeof t.tableAutoSize||t.tableAutoSize,this.imagesByReference=!(!t||"boolean"!=typeof t.imagesByReference)&&t.imagesByReference,this.removeExtraBlanks=!(!t||"boolean"!=typeof t.removeExtraBlanks)&&t.removeExtraBlanks,this.showHidden=!(!t||"boolean"!=typeof t.showHidden)&&t.showHidden,this.removeTagClasses=!(!t||"boolean"!=typeof t.removeTagClasses)&&t.removeTagClasses,this.ignoreStyles=t&&Array.isArray(t.ignoreStyles)?t.ignoreStyles:[],this.imagesByReferenceSuffix=Math.random().toString(36).slice(2,8),this.fontSizes=t&&Array.isArray(t.fontSizes)?t.fontSizes:[10,14,16,18,20,24,28],this.defaultStyles={b:{bold:!0},strong:{bold:!0},u:{decoration:"underline"},del:{decoration:"lineThrough"},s:{decoration:"lineThrough"},em:{italics:!0},i:{italics:!0},h1:{fontSize:24,bold:!0,marginBottom:5},h2:{fontSize:22,bold:!0,marginBottom:5},h3:{fontSize:20,bold:!0,marginBottom:5},h4:{fontSize:18,bold:!0,marginBottom:5},h5:{fontSize:16,bold:!0,marginBottom:5},h6:{fontSize:14,bold:!0,marginBottom:5},a:{color:"blue",decoration:"underline"},strike:{decoration:"lineThrough"},p:{margin:[0,5,0,5]},ul:{marginBottom:5,marginLeft:5},table:{marginBottom:5},th:{bold:!0,fillColor:"#EEEEEE"}},t.customTag&&(this.customTag=t.customTag),t.replaceText&&(this.replaceText=t.replaceText),t&&t.defaultStyles&&this.changeDefaultStyles(t.defaultStyles),this.imagesRef=[]}changeDefaultStyles(e){for(var t in e)if(this.defaultStyles.hasOwnProperty(t))if(e.hasOwnProperty(t)&&!e[t])delete this.defaultStyles[t];else for(var a in e[t])""===e[t][a]?delete this.defaultStyles[t][a]:this.defaultStyles[t][a]=e[t][a];else for(var r in this.defaultStyles[t]={},e[t])this.defaultStyles[t][r]=e[t][r]}getParentWidth(t){const a=t.parentNode;return a?a.style?.width||a.width?Math.min(e.convertToUnit(a.style?.width||a.width)||this.maxWidth,this.maxWidth):this.getParentWidth(a):this.maxWidth}convert(e){return"string"==typeof e?this._parserHTML(e):this._parserBody(e)}_parserHTML(e){this.removeExtraBlanks&&(e=e.replace(/(<\/?(div|p|h1|h2|h3|h4|h5|h6|ol|ul|li)([^>]+)?>)\s+(<\/?(div|p|h1|h2|h3|h4|h5|h6|ol|ul|li))/gi,"$1$4").replace(/(<\/?(div|p|h1|h2|h3|h4|h5|h6|ol|ul|li)([^>]+)?>)\s+(<\/?(div|p|h1|h2|h3|h4|h5|h6|ol|ul|li))/gi,"$1$4").replace(/(<td([^>]+)?>)\s+(<table)/gi,"$1$3").replace(/(<\/table>)\s+(<\/td>)/gi,"$1$2"));const t=new r.JSDOM("<html><body></body></html>").window.document;return t.body.innerHTML=e,this._parserBody(t.body)}_parserBody(e){var t=this.parseElement(e,[]);let a=t.stack||t.text;return"string"==typeof a&&(a={text:a}),this.imagesByReference&&(a={content:a,images:{}},this.imagesRef.forEach((e,t)=>{a.images["img_ref_"+this.imagesByReferenceSuffix+t]=e.startsWith("{")?JSON.parse(e):e})),a}parseElement(t,a){var r,i,o,s,n=t.nodeName.toUpperCase(),l=n.toLowerCase(),c={text:[]},h=this;if(["STYLE","SCRIPT","META","COLGROUP","COL"].indexOf(n)>-1)return"";switch(t.nodeType){case 3:if(t.textContent){r=t.textContent;var d=this.parseStyle(a[a.length-1],!0),p=a.findIndex(function(e){return"PRE"===e.nodeName})>-1;for(o=0;o<d.length;o++)if("preserveLeadingSpaces"===d[o].key){p=d[o].value;break}if(p||(r=r.replace(/\s*\n\s*/g," ")),"function"==typeof this.replaceText&&(r=this.replaceText(r,a)),["TABLE","THEAD","TBODY","TFOOT","TR","UL","OL"].indexOf(a[a.length-1].nodeName)>-1&&(r=r.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")),r)return c={text:r},c=this.applyStyle({ret:c,parents:a})}return"";case 1:if(!this.showHidden&&t.style.display&&"none"===t.style.display||t.style.visibility&&"hidden"===t.style.visibility)return;switch(null!==t.getAttribute("page")&&"1"!==t.getAttribute("page")&&(c.pageBreak="before"),c.nodeName=n,t.id&&(c.id=t.id),a.push(t),t.childNodes&&t.childNodes.length>0&&([].forEach.call(t.childNodes,e=>{var t=h.parseElement(e,a);t&&(Array.isArray(t.text)&&0===t.text.length&&(t.text=" "),c.text.push(t))}),e.searchForStack(c)?(c.stack=c.text.slice(0),delete c.text,c=this.applyStyle({ret:c,parents:[t]})):c=this.applyStyle({ret:c,parents:a})),a.pop(),n){case"DIV":"p"==t.parentNode.nodeName&&(c=this.applyStyle({ret:c,parents:a}));break;case"TABLE":var f;c.table={body:[]};var g=c.stack||c.text;if(Array.isArray(g)){f=0;var y=!1;if(g.forEach(function(e){var t=e.stack||e.text;Array.isArray(t)&&t.forEach(function(e){var t=e.stack||e.text;Array.isArray(t)&&(c.table.body[f]=[],t.forEach(function(e){if(c.table.body[f].push(e),e.colSpan>1)for(o=e.colSpan;--o>0;)c.table.body[f].push({text:" "});e.rowSpan>1&&(y=!0)}),f++)})}),y){var m=c.table.body[0];if(Array.isArray(m))for(var b=m.length,v=c.table.body.length,k=0;k<b;k++)for(var x=0;x<v;x++){var S=c.table.body[x];if(Array.isArray(S)){var A=S[k];if(A.rowSpan>1){for(var T,w=A.rowSpan,C=A.colSpan?A.colSpan:1,O=1;O<=w-1;O++)if(T=C,c.table.body[x+O])for(;T--;)c.table.body[x+O].splice(k,0,{text:""});else A.rowSpan--;x+=w-1}}}}}if(delete c.stack,delete c.text,c=this.applyStyle({ret:c,parents:a.concat([t])}),this.tableAutoSize){var E=[],B=[],R=[],L=[],M=t.getAttribute("width")||t.style.width,N=M.endsWith("%");N?M=Math.round(this.getParentWidth(t)*parseFloat(M.replace(/[^\d\.]/g,""))*.01):isNaN(M)&&(M=e.convertToUnit(M));for(var z=!1,F=-1,U=0;U<t.children.length;U++){z||F++,"COLGROUP"===t.children[U].nodeName.toUpperCase()&&(z=!0)}if(c.table.body.forEach(function(e,t){E.push([]),B.push([]),e.forEach(function(e,a){var r=void 0!==e.width?e.width:"auto";"*"===r&&(r="auto");var i=void 0!==e.height?e.height:"auto";"*"===i&&(i="auto"),"auto"!==r&&e.colSpan>1&&(isNaN(r)?r="auto":r/=e.colSpan),"auto"!==i&&e.rowSpan>1&&(isNaN(i)?i="auto":i/=e.rowSpan),E[t].push(r),B[t].push(i)})}),z){var H=t.children[F];[].forEach.call(H.childNodes,(a,r)=>{var i=a.getAttribute("width")||a.style.width;i.endsWith("%")?R[r]=.01*parseFloat(i.replace(/[^\d\.]/g,""))*this.getParentWidth(t):R[r]=e.convertToUnit(i)})}E.forEach(function(e){e.forEach(function(t,a){var r=typeof R[a];("undefined"===r||"auto"!==t&&"number"===r&&t>R[a]||"auto"!==t&&"auto"===R[a])&&(N&&(t="auto"===t?M/e.length:.01*t.toString().replace("%","")*M),R[a]=t)})}),B.forEach(function(e,t){e.forEach(function(e){var a=typeof L[t];("undefined"===a||"auto"!==e&&"number"===a&&e>L[t]||"auto"!==e&&"auto"===L[t])&&(L[t]=e)})}),R.length>0&&(c.table.widths=R.map(e=>.01*Math.round(100*(e-2*R.length)))),L.length>0&&(c.table.heights=L)}if(t.dataset&&t.dataset.pdfmake){i=t.dataset.pdfmake.replace(/'/g,'"');try{for(s in i=JSON.parse(i))"layout"===s?c.layout=i[s]:c.table[s]=i[s]}catch(e){console.error(e)}}else c.layout="html-table";break;case"TH":case"TD":t.getAttribute("rowspan")&&(c.rowSpan=1*t.getAttribute("rowspan")),t.getAttribute("colspan")&&(c.colSpan=1*t.getAttribute("colspan"));break;case"SVG":c={svg:t.outerHTML.replace(/\n(\s+)?/g,""),nodeName:"SVG"},this.removeTagClasses||(c.style=["html-svg"]);break;case"BR":c.text=[{text:"\n"}];break;case"SUB":case"SUP":c[n.toLowerCase()]={offset:"30%",fontSize:8};break;case"HR":var P={width:514,type:"line",margin:[0,12,0,12],thickness:.5,color:"#000000",left:0};if(t.dataset&&t.dataset.pdfmake){i=t.dataset.pdfmake.replace(/'/g,'"');try{for(s in i=JSON.parse(i))P[s]=i[s]}catch(e){console.error(e)}}c.margin=P.margin,c.canvas=[{type:P.type,x1:P.left,y1:0,x2:P.width,y2:0,lineWidth:P.thickness,lineColor:P.color}],delete c.text;break;case"OL":case"UL":switch(c[l]=(c.stack||c.text).slice(0),delete c.stack,delete c.text,c=this.applyStyle({ret:c,parents:a.concat([t])}),t.getAttribute("start")&&(c.start=1*t.getAttribute("start")),t.getAttribute("type")){case"A":c.type="upper-alpha";break;case"a":c.type="lower-alpha";break;case"I":c.type="upper-roman";break;case"i":c.type="lower-roman"}(c.listStyle||c.listStyleType)&&(c.type=c.listStyle||c.listStyleType);break;case"LI":c.stack&&!c.stack[c.stack.length-1].text&&(r=c.stack.slice(0,-1),c=[{text:r},c.stack[c.stack.length-1]]),Array.isArray(c)&&(c={stack:c});break;case"PRE":c.preserveLeadingSpaces=!0;break;case"IMG":if(c=this.applyStyle({ret:c,parents:a.concat([t])}),this.imagesByReference){var I=t.getAttribute("data-src")||t.getAttribute("src"),W=this.imagesRef.indexOf(I);W>-1?c.image="img_ref_"+this.imagesByReferenceSuffix+W:(c.image="img_ref_"+this.imagesByReferenceSuffix+this.imagesRef.length,this.imagesRef.push(I))}else c.image=t.getAttribute("src");delete c.stack,delete c.text;break;case"A":var $=u(function(e,t){return e=e||{text:""},Array.isArray(e.text)?(e.text=e.text.map(function(e){return $(e,t)}),e):Array.isArray(e.stack)?(e.stack=e.stack.map(function(e){return $(e,t)}),e):(0===t.indexOf("#")?e.linkToDestination=t.slice(1):e.link=t,e)},"setLink");t.getAttribute("href")&&(c=$(c,t.getAttribute("href")),Array.isArray(c.text)&&1===c.text.length&&(c=c.text[0]),c.nodeName="A");break;default:"DIV"===n&&t.dataset&&"columns"===t.dataset.pdfmakeType?c.stack&&(c.columns=c.stack,delete c.stack):"function"==typeof this.customTag&&(c=this.customTag.call(this,{element:t,parents:a,ret:c}))}if(Array.isArray(c.text)&&1===c.text.length&&c.text[0].text&&!c.text[0].nodeName&&(c.text=c.text[0].text),-1===["HR","TABLE"].indexOf(n)&&t.dataset&&t.dataset.pdfmake){i=t.dataset.pdfmake.replace(/'/g,'"');try{for(s in i=JSON.parse(i))c[s]=i[s]}catch(e){console.error(e)}}return c}}applyStyle(e){var t=[],a=e.parents.length-1,r=this;return e.parents.forEach(function(i,o){var s,n=i.nodeName.toLowerCase();if(!r.removeTagClasses){var l="html-"+n;"html-body"!==l&&-1===t.indexOf(l)&&t.unshift(l)}(i.getAttribute("class")||"").split(" ").forEach(function(e){e&&t.push(e)});var c=o!==a;if(r.defaultStyles[n])for(s in r.defaultStyles[n])r.defaultStyles[n].hasOwnProperty(s)&&(!c||c&&-1===s.indexOf("margin")&&-1===s.indexOf("border"))&&("decoration"===s?(Array.isArray(e.ret[s])||(e.ret[s]=[]),r.defaultStyles[n][s]&&-1===e.ret[s].indexOf(r.defaultStyles[n][s])&&e.ret[s].push(r.defaultStyles[n][s])):e.ret[s]=JSON.parse(JSON.stringify(r.defaultStyles[n][s])));"tr"===n&&(c=!1),(s=r.parseStyle(i,c)).forEach(function(t){if("decoration"===t.key)Array.isArray(e.ret[t.key])||(e.ret[t.key]=[]),e.ret[t.key].push(t.value);else if(["ul","ol"].includes(n)&&"alignment"===t.key);else if(e.ret.margin&&0===t.key.indexOf("margin"))switch(t.key){case"marginLeft":e.ret.margin[0]=t.value;break;case"marginTop":e.ret.margin[1]=t.value;break;case"marginRight":e.ret.margin[2]=t.value;break;case"marginBottom":e.ret.margin[3]=t.value}else["minHeight"].includes(t.key)||(e.ret[t.key]=t.value)})}),t.length>0&&(e.ret.style=t),e.ret}borderValueRearrange(e){try{var t=e.split(" ");if(3!==t.length)return e;var a="0px",r="none",i="transparent",o=["dotted","dashed","solid","double","groove","ridge","inset","outset","none","hidden","mix"];return t.forEach(function(e){e.match(/^\d/)?a=e:o.indexOf(e)>-1?r=e:i=e}),a+" "+r+" "+i}catch(t){return e}}parseStyle(t,a){var r=t.getAttribute("style")||"",i=[];r=r.replace(/!important/g,"").split(";");var o=t.getAttribute("width")||t.style.width,s=t.getAttribute("height")||t.style.height;o&&(o.endsWith("%")?o=this.getParentWidth(t)*parseFloat(o.replace(/[^\d\.]/g,""))*.01:isNaN(o)&&(o=e.convertToUnit(o)),r.unshift("width:"+o)),s&&r.unshift("height:"+e.convertToUnit(s+(isNaN(s)?"":"px")));var n=t.getAttribute("color");n&&i.push({key:"color",value:e.parseColor(n).color});var l=t.getAttribute("size");null!==l&&(l=Math.min(Math.max(1,parseInt(l)),7),i.push({key:"fontSize",value:Math.max(this.fontSizes[0],this.fontSizes[l-1])}));var c=r.map(function(e){return e.toLowerCase().split(":")}),h=[],d=t.nodeName.toUpperCase(),u=this;if(c.forEach(function(t){if(2===t.length){var r,o=t[0].trim().toLowerCase(),s=t[1].trim();if(-1===u.ignoreStyles.indexOf(o))switch(o){case"margin":{if(a)break;let t=s.split(" ");1===t.length?t=[t[0],t[0],t[0],t[0]]:2===t.length?t=[t[1],t[0]]:3===t.length?t=[t[1],t[0],t[1],t[2]]:4===t.length&&(t=[t[3],t[0],t[1],t[2]]),t.forEach(function(a,r){t[r]="auto"===a?"":e.convertToUnit(a)}),-1===t.indexOf(!1)&&i.push({key:o,value:s});break}case"line-height":s="string"==typeof s&&"%"===s.slice(-1)?parseFloat(s.slice(0,-1))/100:e.convertToUnit(s),i.push({key:"lineHeight",value:s});break;case"text-align":i.push({key:"alignment",value:s});break;case"font-weight":"bold"===s&&i.push({key:"bold",value:!0});break;case"text-decoration":s=e.toCamelCase(s),["underline","lineThrough","overline"].includes(s)&&i.push({key:"decoration",value:s});break;case"font-style":"italic"===s&&i.push({key:"italics",value:!0});break;case"font-family":i.push({key:"font",value:s.split(",")[0].replace(/"|^'|^\s*|\s*$|'$/g,"").replace(/^([a-z])/g,function(e){return e[0].toUpperCase()}).replace(/ ([a-z])/g,function(e){return e[1].toUpperCase()})});break;case"color":r=e.parseColor(s),i.push({key:"color",value:r.color}),r.opacity<1&&i.push({key:"opacity",value:r.opacity});break;case"background-color":r=e.parseColor(s),i.push({key:"TD"===d||"TH"===d?"fillColor":"background",value:r.color}),r.opacity<1&&i.push({key:"TD"===d||"TH"===d?"fillOpacity":"opacity",value:r.opacity});break;case"text-indent":i.push({key:"leadingIndent",value:e.convertToUnit(s)});break;case"white-space":"nowrap"===s?i.push({key:"noWrap",value:!0}):i.push({key:"preserveLeadingSpaces",value:"break-spaces"===s||"pre"===s.slice(0,3)});break;default:if(0===o.indexOf("border"))a||h.push({key:o,value:s});else{if(a||0===o.indexOf("margin-")||"width"===o||"height"===o)break;if("IMG"===d&&("width"===o||"height"===o)){i.push({key:o,value:e.convertToUnit(s)});break}if(0===o.indexOf("padding"))break;if(o.indexOf("-")>-1&&(o=e.toCamelCase(o)),s){var n=e.convertToUnit(s);if("fontSize"===o&&!1===n){if(!["xx-small","x-small","small","medium","large","x-large","xx-large","xxx-large"].includes(s))break;switch(s){case"xx-small":s=7.2;break;case"x-small":s=9;break;case"small":s=10.7;break;case"medium":s=12;break;case"large":s=14.4;break;case"x-large":s=18;break;case"xx-large":s=24;break;case"xxx-large":s=36}}if(0===o.indexOf("margin")&&"auto"===s)break;i.push({key:o,value:!1===n?s:n})}}}}}),h.length>0){var p=[],f=[];h.forEach(function(t){var a,r=-1;t.key.indexOf("-left")>-1?r=0:t.key.indexOf("-top")>-1?r=1:t.key.indexOf("-right")>-1?r=2:t.key.indexOf("-bottom")>-1&&(r=3);var i,o,s=t.key.split("-");if(1===s.length||2===s.length&&r>=0){if(t.value=u.borderValueRearrange(t.value),o=(i=t.value.split(" "))[0].replace(/(\d*)(\.\d+)?([^\d]+)/g,"$1$2 ").trim(),r>-1)p[r]=o>0;else for(a=0;a<4;a++)p[a]=o>0;if(i.length>2){var n=i.slice(2).join(" ");if(r>-1)f[r]=e.parseColor(n).color;else for(a=0;a<4;a++)f[a]=e.parseColor(n).color}}else r>=0&&"color"===s[2]?f[r]=e.parseColor(t.value).color:r>=0&&"width"===s[2]?p[r]=!/^0[a-z%]*$/.test(String(t.value)):"border-color"===t.key?(i=e.topRightBottomLeftToObject(t.value),f=[e.parseColor(i.left).color,e.parseColor(i.top).color,e.parseColor(i.right).color,e.parseColor(i.bottom).color]):"border-width"===t.key&&(i=e.topRightBottomLeftToObject(t.value),p=[!/^0[a-z%]*$/.test(i.left),!/^0[a-z%]*$/.test(i.top),!/^0[a-z%]*$/.test(i.right),!/^0[a-z%]*$/.test(i.bottom)])});for(var g=0;g<4;g++)p.length>0&&void 0===p[g]&&(p[g]=!0),f.length>0&&void 0===f[g]&&(f[g]="#000000");p.length>0&&i.push({key:"border",value:p}),f.length>0&&i.push({key:"borderColor",value:f})}return i}};async function m({docxFile:e,docxBuffer:t},i){if(e&&l.default.existsSync(e)&&(t=l.default.readFileSync(e)),t){const e=new r.JSDOM("<!DOCTYPE html><html><body></body></html>",{pretendToBeVisual:!0}).window.document.body;await a.renderAsync(t,e,void 0,{inWrapper:!1,ignoreWidth:!0,ignoreHeight:!0,ignoreLastRenderedPageBreak:!0,renderHeaders:!1,renderFooters:!1,useBase64URL:!0,ignoreFonts:!0,renderFootnotes:!1,renderEndnotes:!1,renderComments:!1,renderAltChunks:!1,hideWrapperOnPrint:!0,breakPages:!0});const o=e.innerHTML.replace(/<\/?span[^>]*>/g,""),s=new y({pageSize:i?.pageSize,pageOrientation:i?.pageOrientation||"portrait",pageMargin:i?.pageMargin}).convert(o),d={version:i?.version||"1.7",language:i?.language||"zh-CN",pageSize:i?.pageSize||"A4",pageOrientation:i?.pageOrientation||"portrait",defaultStyle:{font:i?.defaultFont||"SourceHanSerifCN"},pageMargins:i?.pageMargin?[y.convertToUnit(i.pageMargin.left)||36,y.convertToUnit(i.pageMargin.top)||36,y.convertToUnit(i.pageMargin.right)||36,y.convertToUnit(i.pageMargin.bottom)||36]:[36,36,36,36],watermark:i?.watermark,content:s},g=i?.vfs||p("./vfs_fonts.js");c.default.vfs={...h.default,...g},c.default.fonts=i?.fonts||f;const m=c.default.createPdf(d),b={tableLayouts:{"html-table":{hLineWidth:u(()=>.5,"hLineWidth"),vLineWidth:u(()=>.5,"vLineWidth")}}};return{toBuffer:u(()=>new Promise((e,t)=>{try{m.getBuffer(t=>{e(t)},b)}catch(e){t(e)}}),"toBuffer"),toFile:u(e=>new Promise((t,a)=>{try{m.getBuffer(a=>{l.default.writeFileSync(n.default.resolve(e),a),t(n.default.resolve(e))},b)}catch(e){a(e)}}),"toFile"),toStream:u(()=>new Promise((e,t)=>{try{e(m.getStream(b))}catch(e){t(e)}}),"toStream")}}return Promise.reject("Either docx file path<docxFile> or buffer object<docxBuffer> must be provided.")}u(m,"docx2pdf");var b=m;module.exports=b;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docx-make-pdf",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "convert docx file to html then to pdf with pdfmake",
5
5
  "keywords": [
6
6
  "docx",
package/vfs_fonts.js CHANGED
File without changes