jspdf-utils 0.1.11 → 0.1.12
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/html-to-pdf.d.ts +2 -0
- package/dist/html-to-pdf.js +60 -59
- package/package.json +1 -1
package/dist/html-to-pdf.d.ts
CHANGED
|
@@ -98,6 +98,8 @@ export interface TextBorder {
|
|
|
98
98
|
fontSize?: number;
|
|
99
99
|
/** Font family (default: "Arial, sans-serif") */
|
|
100
100
|
fontFamily?: string;
|
|
101
|
+
/** Font weight (default: "normal") */
|
|
102
|
+
fontWeight?: string;
|
|
101
103
|
/** Gap between repetitions in mm (default: fontSize * 0.5) */
|
|
102
104
|
gap?: number;
|
|
103
105
|
/** Distance in mm from the page edge to the text border (default: uses page margins). */
|
package/dist/html-to-pdf.js
CHANGED
|
@@ -22,7 +22,7 @@ const q = {
|
|
|
22
22
|
legal: 25.4,
|
|
23
23
|
tabloid: 25
|
|
24
24
|
};
|
|
25
|
-
function
|
|
25
|
+
function A(t = {}) {
|
|
26
26
|
const e = t.format ?? "a4", [a, o] = q[e], i = t.pageWidth ?? a, n = t.pageHeight ?? o, s = $[e], r = {
|
|
27
27
|
top: s,
|
|
28
28
|
right: s,
|
|
@@ -187,7 +187,7 @@ function O(t, e) {
|
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
189
|
function J(t, e = {}) {
|
|
190
|
-
const a =
|
|
190
|
+
const a = A(e), o = N(), i = E(t, a.pageWidth);
|
|
191
191
|
T(i);
|
|
192
192
|
const n = B(i, a);
|
|
193
193
|
return R(i, n.pageContentPx), j(i, n.pageContentPx), O(i, n.pageContentPx), {
|
|
@@ -291,23 +291,24 @@ function Z(t, e, a, o, i, n, s) {
|
|
|
291
291
|
text: r,
|
|
292
292
|
color: l = "#000000",
|
|
293
293
|
fontSize: h = 2.5,
|
|
294
|
-
fontFamily: c = "Arial, sans-serif"
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
294
|
+
fontFamily: c = "Arial, sans-serif",
|
|
295
|
+
fontWeight: g = "normal"
|
|
296
|
+
} = e, f = h * a, d = (e.gap ?? h * 0.5) * a;
|
|
297
|
+
t.save(), t.fillStyle = l, t.font = `${g} ${f}px ${c}`, t.textBaseline = "middle";
|
|
298
|
+
const m = t.measureText(r).width, x = m + d, w = f * 0.2, b = (p, u, W) => {
|
|
299
|
+
for (let y = p; y < u; y += x)
|
|
300
|
+
if (y + m <= u)
|
|
301
|
+
W(y, r);
|
|
301
302
|
else
|
|
302
|
-
for (let
|
|
303
|
-
const
|
|
304
|
-
if (
|
|
305
|
-
y
|
|
303
|
+
for (let M = r.length - 1; M >= 1; M--) {
|
|
304
|
+
const H = r.substring(0, M);
|
|
305
|
+
if (y + t.measureText(H).width <= u) {
|
|
306
|
+
W(y, H);
|
|
306
307
|
break;
|
|
307
308
|
}
|
|
308
309
|
}
|
|
309
|
-
},
|
|
310
|
-
|
|
310
|
+
}, v = o + w, C = o + n - w;
|
|
311
|
+
b(v, C, (p, u) => t.fillText(u, p, i)), b(v, C, (p, u) => t.fillText(u, p, i + s)), t.save(), t.translate(o, i + s), t.rotate(-Math.PI / 2), b(w, s - w, (p, u) => t.fillText(u, p, 0)), t.restore(), t.save(), t.translate(o + n, i), t.rotate(Math.PI / 2), b(w, s - w, (p, u) => t.fillText(u, p, 0)), t.restore(), t.restore();
|
|
311
312
|
}
|
|
312
313
|
function k(t, e) {
|
|
313
314
|
return Q(t.margin, e);
|
|
@@ -358,7 +359,7 @@ async function F(t, e, a, o, i, n, s, r) {
|
|
|
358
359
|
}
|
|
359
360
|
}
|
|
360
361
|
async function X(t, e = {}) {
|
|
361
|
-
const { imageFormat: a = "JPEG", imageQuality: o = 1, scale: i = 2 } = e, n =
|
|
362
|
+
const { imageFormat: a = "JPEG", imageQuality: o = 1, scale: i = 2 } = e, n = A(e), s = N(), r = E(t, n.pageWidth);
|
|
362
363
|
r.style.opacity = "1", r.style.left = "-99999px", T(r);
|
|
363
364
|
const l = B(r, n);
|
|
364
365
|
R(r, l.pageContentPx), j(r, l.pageContentPx), O(r, l.pageContentPx);
|
|
@@ -366,54 +367,54 @@ async function X(t, e = {}) {
|
|
|
366
367
|
const h = await P(r, {
|
|
367
368
|
scale: i,
|
|
368
369
|
backgroundColor: "#ffffff"
|
|
369
|
-
}), { jsPDF: c } = await import("jspdf"), g = n.pageWidth - n.margin.left - n.margin.right, f = n.pageHeight - n.margin.top - n.margin.bottom, d = h.width, m = f / g * d,
|
|
370
|
-
orientation:
|
|
370
|
+
}), { jsPDF: c } = await import("jspdf"), g = n.pageWidth - n.margin.left - n.margin.right, f = n.pageHeight - n.margin.top - n.margin.bottom, d = h.width, m = f / g * d, x = Math.ceil(h.height / m), w = n.pageWidth > n.pageHeight ? "l" : "p", b = new c({
|
|
371
|
+
orientation: w,
|
|
371
372
|
unit: "mm",
|
|
372
373
|
format: [n.pageWidth, n.pageHeight]
|
|
373
374
|
});
|
|
374
|
-
for (let v = 0; v <
|
|
375
|
-
const
|
|
375
|
+
for (let v = 0; v < x; v++) {
|
|
376
|
+
const C = Math.min(
|
|
376
377
|
m,
|
|
377
378
|
h.height - v * m
|
|
378
|
-
),
|
|
379
|
-
|
|
380
|
-
const
|
|
381
|
-
if (!
|
|
382
|
-
|
|
379
|
+
), p = document.createElement("canvas");
|
|
380
|
+
p.width = d, p.height = C;
|
|
381
|
+
const u = p.getContext("2d");
|
|
382
|
+
if (!u) throw new Error("Could not get canvas context");
|
|
383
|
+
u.fillStyle = "#ffffff", u.fillRect(0, 0, d, C), u.drawImage(
|
|
383
384
|
h,
|
|
384
385
|
0,
|
|
385
386
|
v * m,
|
|
386
387
|
d,
|
|
387
|
-
|
|
388
|
+
C,
|
|
388
389
|
0,
|
|
389
390
|
0,
|
|
390
391
|
d,
|
|
391
|
-
|
|
392
|
+
C
|
|
392
393
|
);
|
|
393
|
-
const
|
|
394
|
+
const W = p.toDataURL(
|
|
394
395
|
`image/${a.toLowerCase()}`,
|
|
395
396
|
o
|
|
396
397
|
);
|
|
397
|
-
v > 0 &&
|
|
398
|
-
const
|
|
399
|
-
|
|
400
|
-
|
|
398
|
+
v > 0 && b.addPage([n.pageWidth, n.pageHeight], w);
|
|
399
|
+
const y = C / d * g;
|
|
400
|
+
b.addImage(
|
|
401
|
+
W,
|
|
401
402
|
a,
|
|
402
403
|
n.margin.left,
|
|
403
404
|
n.margin.top,
|
|
404
405
|
g,
|
|
405
|
-
|
|
406
|
+
y,
|
|
406
407
|
void 0,
|
|
407
408
|
"FAST"
|
|
408
409
|
);
|
|
409
410
|
}
|
|
410
|
-
return e.marginContent && await z(
|
|
411
|
+
return e.marginContent && await z(b, e.marginContent, e), b;
|
|
411
412
|
} finally {
|
|
412
413
|
r.remove(), s();
|
|
413
414
|
}
|
|
414
415
|
}
|
|
415
416
|
async function K(t, e = {}) {
|
|
416
|
-
const { imageFormat: a = "PNG", imageQuality: o = 1, scale: i = 2 } = e, n =
|
|
417
|
+
const { imageFormat: a = "PNG", imageQuality: o = 1, scale: i = 2 } = e, n = A(e), s = N(), r = E(t, n.pageWidth);
|
|
417
418
|
r.style.opacity = "1", r.style.left = "-99999px", T(r);
|
|
418
419
|
const l = B(r, n);
|
|
419
420
|
R(r, l.pageContentPx), j(r, l.pageContentPx), O(r, l.pageContentPx);
|
|
@@ -421,48 +422,48 @@ async function K(t, e = {}) {
|
|
|
421
422
|
const h = await P(r, {
|
|
422
423
|
scale: i,
|
|
423
424
|
backgroundColor: "#ffffff"
|
|
424
|
-
}), c = n.pageWidth - n.margin.left - n.margin.right, g = n.pageHeight - n.margin.top - n.margin.bottom, f = h.width, d = g / c * f, m = f / c,
|
|
425
|
-
for (let
|
|
426
|
-
const
|
|
425
|
+
}), c = n.pageWidth - n.margin.left - n.margin.right, g = n.pageHeight - n.margin.top - n.margin.bottom, f = h.width, d = g / c * f, m = f / c, x = Math.round(n.pageWidth * m), w = Math.round(n.pageHeight * m), b = Math.round(n.margin.top * m), v = Math.round(n.margin.left * m), C = Math.ceil(h.height / d), p = [], { marginContent: u } = e, W = u ? await D(u, n, i) : {};
|
|
426
|
+
for (let y = 0; y < C; y++) {
|
|
427
|
+
const M = Math.min(
|
|
427
428
|
d,
|
|
428
|
-
h.height -
|
|
429
|
-
),
|
|
430
|
-
|
|
431
|
-
const
|
|
432
|
-
if (!
|
|
433
|
-
|
|
429
|
+
h.height - y * d
|
|
430
|
+
), H = document.createElement("canvas");
|
|
431
|
+
H.width = x, H.height = w;
|
|
432
|
+
const S = H.getContext("2d");
|
|
433
|
+
if (!S) throw new Error("Could not get canvas context");
|
|
434
|
+
S.fillStyle = "#ffffff", S.fillRect(0, 0, x, w), S.drawImage(
|
|
434
435
|
h,
|
|
435
436
|
0,
|
|
436
|
-
|
|
437
|
+
y * d,
|
|
437
438
|
f,
|
|
438
|
-
|
|
439
|
+
M,
|
|
439
440
|
v,
|
|
440
|
-
|
|
441
|
+
b,
|
|
441
442
|
f,
|
|
442
|
-
|
|
443
|
-
),
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
443
|
+
M
|
|
444
|
+
), u && await F(
|
|
445
|
+
S,
|
|
446
|
+
u,
|
|
447
|
+
W,
|
|
447
448
|
n,
|
|
448
449
|
m,
|
|
449
|
-
|
|
450
|
-
|
|
450
|
+
y + 1,
|
|
451
|
+
C,
|
|
451
452
|
i
|
|
452
|
-
),
|
|
453
|
-
|
|
453
|
+
), p.push(
|
|
454
|
+
H.toDataURL(
|
|
454
455
|
`image/${a.toLowerCase()}`,
|
|
455
456
|
o
|
|
456
457
|
)
|
|
457
458
|
);
|
|
458
459
|
}
|
|
459
|
-
return
|
|
460
|
+
return p;
|
|
460
461
|
} finally {
|
|
461
462
|
r.remove(), s();
|
|
462
463
|
}
|
|
463
464
|
}
|
|
464
465
|
async function tt(t, e, a = {}) {
|
|
465
|
-
const o =
|
|
466
|
+
const o = A(a), i = await K(t, a);
|
|
466
467
|
e.innerHTML = "", Object.assign(e.style, {
|
|
467
468
|
direction: "ltr",
|
|
468
469
|
width: "fit-content",
|
|
@@ -486,7 +487,7 @@ async function tt(t, e, a = {}) {
|
|
|
486
487
|
}
|
|
487
488
|
}
|
|
488
489
|
async function z(t, e, a = {}) {
|
|
489
|
-
const o =
|
|
490
|
+
const o = A(a), i = t.getNumberOfPages(), n = 2, s = n * (96 / 25.4), r = Math.round(o.pageWidth * s), l = Math.round(o.pageHeight * s), h = await D(e, o, n);
|
|
490
491
|
for (let c = 1; c <= i; c++) {
|
|
491
492
|
t.setPage(c);
|
|
492
493
|
const g = document.createElement("canvas");
|
package/package.json
CHANGED