ztxkutils 2.10.16 → 2.10.17
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/print.js +28 -13
- package/package.json +1 -1
package/dist/print.js
CHANGED
@@ -100,18 +100,23 @@ function addPdfWaterHandle(pdf, waterBase64) {
|
|
100
100
|
/**
|
101
101
|
* html转pdf
|
102
102
|
*/
|
103
|
-
function createPdf(canvas, pdf, noWater, positionX) {
|
103
|
+
function createPdf(canvas, pdf, noWater, positionX, options) {
|
104
104
|
var contentWidth = canvas.width;
|
105
105
|
var contentHeight = canvas.height;
|
106
|
+
var setWidth = (options === null || options === void 0 ? void 0 : options.width) || 592.28;
|
107
|
+
var setHeight = (options === null || options === void 0 ? void 0 : options.height) || 841.89;
|
106
108
|
// 一页pdf显示html页面生成的canvas高度
|
107
|
-
|
109
|
+
// const pageHeight = (contentWidth / 592.28) * 841.89;
|
110
|
+
var pageHeight = (contentWidth / setWidth) * setHeight;
|
108
111
|
// 未生成pdf的html页面高度
|
109
112
|
var leftHeight = contentHeight;
|
110
113
|
// 页面拍内衣
|
111
114
|
var position = 0;
|
112
115
|
//a4纸的尺寸[595.28,841.89],html页面生成的canvas在pdf中图片的宽高
|
113
|
-
|
114
|
-
|
116
|
+
// const imgWidth = 595.28;
|
117
|
+
// const imgHeight = (592.28 / contentWidth) * contentHeight;
|
118
|
+
var imgWidth = setWidth - (positionX || 20) - 10;
|
119
|
+
var imgHeight = (setWidth / contentWidth) * contentHeight;
|
115
120
|
var pageData = canvas.toDataURL('image/jpeg', 1.0);
|
116
121
|
//有两个高度需要区分,一个是html页面的实际高度,和生成pdf的页面高度(841.89)
|
117
122
|
//当内容未超过pdf一页显示的范围,无需分页
|
@@ -136,7 +141,8 @@ function createPdf(canvas, pdf, noWater, positionX) {
|
|
136
141
|
addPdfWaterHandle(pdf, waterBase64);
|
137
142
|
}
|
138
143
|
leftHeight -= pageHeight;
|
139
|
-
position -= 841.89;
|
144
|
+
// position -= 841.89;
|
145
|
+
position -= setHeight;
|
140
146
|
//避免添加空白页
|
141
147
|
if (leftHeight > 0) {
|
142
148
|
pdf.addPage();
|
@@ -147,7 +153,8 @@ function createPdf(canvas, pdf, noWater, positionX) {
|
|
147
153
|
function htmlToPdf(_a) {
|
148
154
|
var pageClassName = _a.pageClassName, dom = _a.dom, pdfName = _a.pdfName, isShowPage = _a.isShowPage, noWater = _a.noWater, pdfOptions = _a.pdfOptions, imgPositionX = _a.imgPositionX;
|
149
155
|
var allDom = document.querySelectorAll(pageClassName ? pageClassName : '.html2canvas-container-page');
|
150
|
-
var
|
156
|
+
var format = (pdfOptions === null || pdfOptions === void 0 ? void 0 : pdfOptions.format) || [632.28, 841.89];
|
157
|
+
var pdf = new jsPDF(__assign({ unit: 'pt', format: format }, (pdfOptions || {})));
|
151
158
|
if (allDom.length > 0 && isShowPage) {
|
152
159
|
var allDomArray = Array.prototype.slice.call(allDom);
|
153
160
|
var promiseAllDomArray_1 = allDomArray.map(function (dom) {
|
@@ -171,7 +178,10 @@ function htmlToPdf(_a) {
|
|
171
178
|
return [4 /*yield*/, item];
|
172
179
|
case 2:
|
173
180
|
canvas = _a.sent();
|
174
|
-
createPdf(canvas, pdf, noWater, imgPositionX
|
181
|
+
createPdf(canvas, pdf, noWater, imgPositionX, {
|
182
|
+
width: format === null || format === void 0 ? void 0 : format[0],
|
183
|
+
height: format === null || format === void 0 ? void 0 : format[1],
|
184
|
+
});
|
175
185
|
if (i < promiseAllDomArray_1.length) {
|
176
186
|
pdf.addPage();
|
177
187
|
}
|
@@ -189,7 +199,10 @@ function htmlToPdf(_a) {
|
|
189
199
|
}
|
190
200
|
else {
|
191
201
|
return html2canvas(dom, { scale: 2 }).then(function (canvas) {
|
192
|
-
createPdf(canvas, pdf, noWater, imgPositionX
|
202
|
+
createPdf(canvas, pdf, noWater, imgPositionX, {
|
203
|
+
width: format === null || format === void 0 ? void 0 : format[0],
|
204
|
+
height: format === null || format === void 0 ? void 0 : format[1],
|
205
|
+
});
|
193
206
|
pdf.save(pdfName + ".pdf");
|
194
207
|
return pdf;
|
195
208
|
});
|
@@ -225,15 +238,17 @@ function htmlToPdfNoCanvas(_a) {
|
|
225
238
|
pdfs_1 = [];
|
226
239
|
return [2 /*return*/, (function () {
|
227
240
|
return __awaiter(this, void 0, void 0, function () {
|
228
|
-
var _loop_1, _i, allDomArray_2, item;
|
241
|
+
var i, _loop_1, _i, allDomArray_2, item;
|
229
242
|
return __generator(this, function (_a) {
|
230
243
|
switch (_a.label) {
|
231
244
|
case 0:
|
245
|
+
i = 0;
|
232
246
|
_loop_1 = function (item) {
|
233
247
|
var pdf, pageWidth;
|
234
248
|
return __generator(this, function (_b) {
|
235
249
|
switch (_b.label) {
|
236
250
|
case 0:
|
251
|
+
i++;
|
237
252
|
pdf = new jsPDF(pdfOptions);
|
238
253
|
pageWidth = pdf.internal.pageSize.width - pageMarginX * 2;
|
239
254
|
setPdfVersion(pdf);
|
@@ -246,7 +261,7 @@ function htmlToPdfNoCanvas(_a) {
|
|
246
261
|
windowWidth: pageWidth,
|
247
262
|
callback: function (res) {
|
248
263
|
// 添加呈现的HTML所需的页面(从第2页开始)
|
249
|
-
for (var
|
264
|
+
for (var i_1 = 2, j = res.internal.getNumberOfPages(); i_1 <= j; i_1++) {
|
250
265
|
pdf.addPage(pageFormat, pageOrient);
|
251
266
|
}
|
252
267
|
// 正确呈现文档
|
@@ -256,15 +271,15 @@ function htmlToPdfNoCanvas(_a) {
|
|
256
271
|
width: pageWidth,
|
257
272
|
windowWidth: pageWidth,
|
258
273
|
callback: function () {
|
259
|
-
for (var
|
260
|
-
pdf.setPage(
|
274
|
+
for (var i_2 = 1, j = res.internal.getNumberOfPages(); i_2 <= j; i_2++) {
|
275
|
+
pdf.setPage(i_2);
|
261
276
|
// 添加水印
|
262
277
|
if (isAddWater) {
|
263
278
|
setPdfWater(pdf, waterBase64, imgWidth, imgHeight);
|
264
279
|
}
|
265
280
|
}
|
266
281
|
if (isDownload) {
|
267
|
-
pdf.save(pdfName + ".pdf");
|
282
|
+
pdf.save(pdfName + "_" + i + ".pdf");
|
268
283
|
}
|
269
284
|
pdfBase64_1.push(pdf.output('dataurlstring'));
|
270
285
|
pdfs_1.push(pdf);
|