ztxkutils 2.8.2 → 2.8.5

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/dist/index.js CHANGED
@@ -2,7 +2,7 @@ export { c as authority } from './authority-fad2028d.js';
2
2
  export { d as dataModel } from './dataModel-1fbaff40.js';
3
3
  export { t as tools } from './tools-4de9d743.js';
4
4
  export { v as validate } from './validate-3e15dd74.js';
5
- export { r as request } from './request-e17553d9.js';
5
+ export { r as request } from './request-e7a40fd7.js';
6
6
  export { r as reqUrl } from './reqUrl-88fcc5c5.js';
7
7
  import './tslib.es6-f9459658.js';
8
8
  import 'dayjs';
package/dist/print.d.ts CHANGED
@@ -39,7 +39,7 @@ export interface IPdfOption {
39
39
  /** 上下边距 */
40
40
  pageMarginY?: number;
41
41
  }
42
- export declare function htmlToPdfNoCanvas({ pageClassName, dom, isShowPage, fileBinary, pdfName, isDownload, pdfOption, }: {
42
+ export declare function htmlToPdfNoCanvas({ pageClassName, dom, isShowPage, fileBinary, pdfName, isDownload, pdfOption, isAddWater, waterBase64, imgWidth, imgHeight, }: {
43
43
  pageClassName?: string;
44
44
  dom: HTMLElement;
45
45
  isShowPage?: boolean;
@@ -47,5 +47,11 @@ export declare function htmlToPdfNoCanvas({ pageClassName, dom, isShowPage, file
47
47
  pdfName?: string;
48
48
  isDownload?: boolean;
49
49
  pdfOption?: IPdfOption;
50
+ /** 是否添加水印 */
51
+ isAddWater?: boolean;
52
+ /** 水印base 64字符串 */
53
+ waterBase64?: string;
54
+ imgWidth?: number;
55
+ imgHeight?: number;
50
56
  }): Promise<unknown>;
51
57
  export {};
package/dist/print.js CHANGED
@@ -150,18 +150,18 @@ function htmlToPdf(_a) {
150
150
  }
151
151
  function htmlToPdfNoCanvas(_a) {
152
152
  var _b, _c, _d;
153
- var pageClassName = _a.pageClassName, dom = _a.dom, isShowPage = _a.isShowPage, fileBinary = _a.fileBinary, pdfName = _a.pdfName, isDownload = _a.isDownload, pdfOption = _a.pdfOption;
153
+ var pageClassName = _a.pageClassName, dom = _a.dom, isShowPage = _a.isShowPage, fileBinary = _a.fileBinary, pdfName = _a.pdfName, isDownload = _a.isDownload, pdfOption = _a.pdfOption, isAddWater = _a.isAddWater, waterBase64 = _a.waterBase64, imgWidth = _a.imgWidth, imgHeight = _a.imgHeight;
154
154
  return __awaiter(this, void 0, void 0, function () {
155
155
  var allDom, pageFormat, pageOrient, pageMarginX, pageMarginY, pdfOptions, allDomArray_1, pdfBase64_1, pdfs_1, pdf_1, pageWidth_1;
156
156
  return __generator(this, function (_e) {
157
157
  allDom = document.querySelectorAll(pageClassName ? pageClassName : '.html2canvas-container-page');
158
- pageFormat = pdfOption.pageFormat ? pdfOption.pageFormat : 'a4';
159
- pageOrient = pdfOption.pageOrient ? pdfOption.pageOrient : 'p';
160
- pageMarginX = (_b = pdfOption.pageMarginX) !== null && _b !== void 0 ? _b : 10;
161
- pageMarginY = (_c = pdfOption.pageMarginY) !== null && _c !== void 0 ? _c : 10;
158
+ pageFormat = (pdfOption === null || pdfOption === void 0 ? void 0 : pdfOption.pageFormat) ? pdfOption.pageFormat : 'a4';
159
+ pageOrient = (pdfOption === null || pdfOption === void 0 ? void 0 : pdfOption.pageOrient) ? pdfOption.pageOrient : 'p';
160
+ pageMarginX = (_b = pdfOption === null || pdfOption === void 0 ? void 0 : pdfOption.pageMarginX) !== null && _b !== void 0 ? _b : 10;
161
+ pageMarginY = (_c = pdfOption === null || pdfOption === void 0 ? void 0 : pdfOption.pageMarginY) !== null && _c !== void 0 ? _c : 10;
162
162
  pdfOptions = {
163
163
  // 是否压缩生成的PDF
164
- compress: (_d = pdfOption.pageMarginY) !== null && _d !== void 0 ? _d : true,
164
+ compress: (_d = pdfOption === null || pdfOption === void 0 ? void 0 : pdfOption.pageMarginY) !== null && _d !== void 0 ? _d : true,
165
165
  // 格式
166
166
  format: pageFormat,
167
167
  hotfixes: ['px_scaling'],
@@ -188,15 +188,8 @@ function htmlToPdfNoCanvas(_a) {
188
188
  case 0:
189
189
  pdf = new jsPDF(pdfOptions);
190
190
  pageWidth = pdf.internal.pageSize.width - pageMarginX * 2;
191
- try {
192
- pdf.__private__.setPdfVersion('1.7');
193
- }
194
- catch (err) {
195
- console.log(err);
196
- }
197
- pdf.addFileToVFS('microsoft-yahei.ttf', fileBinary === null || fileBinary === void 0 ? void 0 : fileBinary.data);
198
- pdf.addFont('microsoft-yahei.ttf', 'microsoft-yahei', 'normal');
199
- pdf.setFont('microsoft-yahei');
191
+ setPdfVersion(pdf);
192
+ supportJsPdfChinese(pdf, fileBinary);
200
193
  return [4 /*yield*/, new Promise(function (resolve) {
201
194
  new jsPDF(pdfOptions).html(item, {
202
195
  autoPaging: 'text',
@@ -215,6 +208,13 @@ function htmlToPdfNoCanvas(_a) {
215
208
  width: pageWidth,
216
209
  windowWidth: pageWidth,
217
210
  callback: function () {
211
+ for (var i = 1, j = res.internal.getNumberOfPages(); i <= j; i++) {
212
+ pdf.setPage(i);
213
+ // 添加水印
214
+ if (isAddWater) {
215
+ setPdfWater(pdf, waterBase64, imgWidth, imgHeight);
216
+ }
217
+ }
218
218
  if (isDownload) {
219
219
  pdf.save(pdfName + ".pdf");
220
220
  }
@@ -256,15 +256,8 @@ function htmlToPdfNoCanvas(_a) {
256
256
  else {
257
257
  pdf_1 = new jsPDF(pdfOptions);
258
258
  pageWidth_1 = pdf_1.internal.pageSize.width - pageMarginX * 2;
259
- try {
260
- pdf_1.__private__.setPdfVersion('1.7');
261
- }
262
- catch (err) {
263
- console.log(err);
264
- }
265
- pdf_1.addFileToVFS('microsoft-yahei.ttf', fileBinary === null || fileBinary === void 0 ? void 0 : fileBinary.data);
266
- pdf_1.addFont('microsoft-yahei.ttf', 'microsoft-yahei', 'normal');
267
- pdf_1.setFont('microsoft-yahei');
259
+ setPdfVersion(pdf_1);
260
+ supportJsPdfChinese(pdf_1, fileBinary);
268
261
  return [2 /*return*/, new Promise(function (resolve) {
269
262
  new jsPDF(pdfOptions).html(dom, {
270
263
  autoPaging: 'text',
@@ -283,6 +276,13 @@ function htmlToPdfNoCanvas(_a) {
283
276
  width: pageWidth_1,
284
277
  windowWidth: pageWidth_1,
285
278
  callback: function () {
279
+ for (var i = 1, j = res.internal.getNumberOfPages(); i <= j; i++) {
280
+ pdf_1.setPage(i);
281
+ // 添加水印
282
+ if (isAddWater) {
283
+ setPdfWater(pdf_1, waterBase64, imgWidth, imgHeight);
284
+ }
285
+ }
286
286
  if (isDownload) {
287
287
  pdf_1.save(pdfName + ".pdf");
288
288
  }
@@ -298,6 +298,45 @@ function htmlToPdfNoCanvas(_a) {
298
298
  }
299
299
  });
300
300
  });
301
+ }
302
+ /**
303
+ * @author 陈亚雄
304
+ * @description 设置pdf版本号,契约锁需要1.7以上的pdf版本
305
+ * @param pdf pdf实例
306
+ */
307
+ function setPdfVersion(pdf) {
308
+ try {
309
+ pdf.__private__.setPdfVersion('1.7');
310
+ }
311
+ catch (err) {
312
+ console.log(err);
313
+ }
314
+ }
315
+ /**
316
+ * @author 陈亚雄
317
+ * @description jspdf支持中文字符
318
+ * @param pdf pdf实例
319
+ * @param fileBinary 中文字符编码base64串
320
+ */
321
+ function supportJsPdfChinese(pdf, fileBinary) {
322
+ pdf.addFileToVFS('microsoft-yahei.ttf', fileBinary === null || fileBinary === void 0 ? void 0 : fileBinary.data);
323
+ pdf.addFont('microsoft-yahei.ttf', 'microsoft-yahei', 'normal');
324
+ pdf.setFont('microsoft-yahei');
325
+ }
326
+ /**
327
+ * @author 陈亚雄
328
+ * @description 为pdf添加水印,每页添加6个水印
329
+ * @param pdf pdf实例
330
+ */
331
+ function setPdfWater(pdf, waterBase64, imgWidth, imgHeight) {
332
+ if (waterBase64 && imgWidth && imgHeight) {
333
+ pdf.addImage(waterBase64, 'PNG', 20, 20, imgWidth, imgHeight, '1');
334
+ pdf.addImage(waterBase64, 'PNG', 20 + imgWidth, 20, imgWidth, imgHeight, '2');
335
+ pdf.addImage(waterBase64, 'PNG', 20, 20 + imgHeight, imgWidth, imgHeight, '3');
336
+ pdf.addImage(waterBase64, 'PNG', 20 + imgWidth, 20 + imgHeight, imgWidth, imgHeight, '4');
337
+ pdf.addImage(waterBase64, 'PNG', 20, 20 + imgHeight + imgHeight, imgWidth, imgHeight, '5');
338
+ pdf.addImage(waterBase64, 'PNG', 20 + imgWidth, 20 + imgHeight + imgHeight, imgWidth, imgHeight, '6');
339
+ }
301
340
  }
302
341
 
303
342
  export { addWaterHandle, htmlToPdf, htmlToPdfNoCanvas, printCurrentDom, removeWaterHandle };