Skip to content

Commit 4562ce8

Browse files
authored
4.2.1
1 parent 4155c48 commit 4562ce8

File tree

101 files changed

+545
-358
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+545
-358
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jspdf",
3-
"version": "4.2.0",
3+
"version": "4.2.1",
44
"homepage": "https://github.com/parallax/jsPDF",
55
"description": "PDF Document creation from JavaScript",
66
"main": [

dist/jspdf.es.js

Lines changed: 62 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/** @license
22
*
33
* jsPDF - PDF Document creation from JavaScript
4-
* Version 4.2.0 Built on 2026-02-19T09:43:09.013Z
4+
* Version 4.2.1 Built on 2026-03-17T11:11:27.057Z
55
* CommitID 00000000
66
*
77
* Copyright (c) 2010-2025 James Hall <james@parall.ax>, https://github.com/MrRio/jsPDF
@@ -3360,6 +3360,35 @@ function jsPDF(options) {
33603360
type: "application/pdf"
33613361
});
33623362
};
3363+
var clearDomNode = function clearDomNode(node) {
3364+
while (node.firstChild) {
3365+
node.removeChild(node.firstChild);
3366+
}
3367+
};
3368+
var initializeNewWindow = function initializeNewWindow(window) {
3369+
var targetDocument = window.document;
3370+
var html = targetDocument.documentElement;
3371+
var head = targetDocument.head;
3372+
var body = targetDocument.body;
3373+
var style;
3374+
if (!head) {
3375+
head = targetDocument.createElement("head");
3376+
html.appendChild(head);
3377+
}
3378+
if (!body) {
3379+
body = targetDocument.createElement("body");
3380+
html.appendChild(body);
3381+
}
3382+
clearDomNode(head);
3383+
clearDomNode(body);
3384+
style = targetDocument.createElement("style");
3385+
style.appendChild(targetDocument.createTextNode("html, body { padding: 0; margin: 0; } iframe { width: 100%; height: 100%; border: 0;}"));
3386+
head.appendChild(style);
3387+
return {
3388+
document: targetDocument,
3389+
body: body
3390+
};
3391+
};
33633392

33643393
/**
33653394
* Generates the PDF document.
@@ -3422,19 +3451,28 @@ function jsPDF(options) {
34223451
} catch (e) {
34233452
dataURI = btoa(unescape(encodeURIComponent(pdfDocument)));
34243453
}
3425-
return "data:application/pdf;filename=" + options.filename + ";base64," + dataURI;
3454+
return "data:application/pdf;filename=" + encodeURIComponent(options.filename) + ";base64," + dataURI;
34263455
case "pdfobjectnewwindow":
34273456
if (Object.prototype.toString.call(globalObject) === "[object Window]") {
34283457
var pdfObjectUrl = "https://cdnjs.cloudflare.com/ajax/libs/pdfobject/2.1.1/pdfobject.min.js";
3429-
var integrity = ' integrity="sha512-4ze/a9/4jqu+tX9dfOqJYSvyYd5M6qum/3HpCLr+/Jqf0whc37VUbkpNGHR7/8pSnCFw47T1fmIpwBV7UySh3g==" crossorigin="anonymous"';
3430-
if (options.pdfObjectUrl) {
3458+
var useDefaultPdfObjectUrl = !options.pdfObjectUrl;
3459+
if (!useDefaultPdfObjectUrl) {
34313460
pdfObjectUrl = options.pdfObjectUrl;
3432-
integrity = "";
34333461
}
3434-
var htmlForNewWindow = "<html>" + '<style>html, body { padding: 0; margin: 0; } iframe { width: 100%; height: 100%; border: 0;} </style><body><script src="' + pdfObjectUrl + '"' + integrity + '></script><script >PDFObject.embed("' + this.output("dataurlstring") + '", ' + JSON.stringify(options) + ");</script></body></html>";
34353462
var nW = globalObject.open();
34363463
if (nW !== null) {
3437-
nW.document.write(htmlForNewWindow);
3464+
var initializedPdfObjectWindow = initializeNewWindow(nW);
3465+
var pdfObjectScript = initializedPdfObjectWindow.document.createElement("script");
3466+
var scope = this;
3467+
pdfObjectScript.src = pdfObjectUrl;
3468+
if (useDefaultPdfObjectUrl) {
3469+
pdfObjectScript.integrity = "sha512-4ze/a9/4jqu+tX9dfOqJYSvyYd5M6qum/3HpCLr+/Jqf0whc37VUbkpNGHR7/8pSnCFw47T1fmIpwBV7UySh3g==";
3470+
pdfObjectScript.crossOrigin = "anonymous";
3471+
}
3472+
pdfObjectScript.onload = function () {
3473+
nW.PDFObject.embed(scope.output("dataurlstring"), options);
3474+
};
3475+
initializedPdfObjectWindow.body.appendChild(pdfObjectScript);
34383476
}
34393477
return nW;
34403478
} else {
@@ -3443,26 +3481,34 @@ function jsPDF(options) {
34433481
case "pdfjsnewwindow":
34443482
if (Object.prototype.toString.call(globalObject) === "[object Window]") {
34453483
var pdfJsUrl = options.pdfJsUrl || "examples/PDF.js/web/viewer.html";
3446-
var htmlForPDFjsNewWindow = "<html>" + "<style>html, body { padding: 0; margin: 0; } iframe { width: 100%; height: 100%; border: 0;} </style>" + '<body><iframe id="pdfViewer" src="' + pdfJsUrl + "?file=&downloadName=" + options.filename + '" width="500px" height="400px" />' + "</body></html>";
34473484
var PDFjsNewWindow = globalObject.open();
34483485
if (PDFjsNewWindow !== null) {
3449-
PDFjsNewWindow.document.write(htmlForPDFjsNewWindow);
3486+
var initializedPdfJsWindow = initializeNewWindow(PDFjsNewWindow);
3487+
var pdfViewer = initializedPdfJsWindow.document.createElement("iframe");
3488+
var pdfJsQueryChar = pdfJsUrl.indexOf("?") === -1 ? "?" : "&";
34503489
var scope = this;
3451-
PDFjsNewWindow.document.documentElement.querySelector("#pdfViewer").onload = function () {
3490+
pdfViewer.id = "pdfViewer";
3491+
pdfViewer.width = "500px";
3492+
pdfViewer.height = "400px";
3493+
pdfViewer.src = pdfJsUrl + pdfJsQueryChar + "file=&downloadName=" + encodeURIComponent(options.filename);
3494+
pdfViewer.onload = function () {
34523495
PDFjsNewWindow.document.title = options.filename;
3453-
PDFjsNewWindow.document.documentElement.querySelector("#pdfViewer").contentWindow.PDFViewerApplication.open(scope.output("bloburl"));
3496+
pdfViewer.contentWindow.PDFViewerApplication.open(scope.output("bloburl"));
34543497
};
3498+
initializedPdfJsWindow.body.appendChild(pdfViewer);
34553499
}
34563500
return PDFjsNewWindow;
34573501
} else {
34583502
throw new Error("The option pdfjsnewwindow just works in a browser-environment.");
34593503
}
34603504
case "dataurlnewwindow":
34613505
if (Object.prototype.toString.call(globalObject) === "[object Window]") {
3462-
var htmlForDataURLNewWindow = "<html>" + "<style>html, body { padding: 0; margin: 0; } iframe { width: 100%; height: 100%; border: 0;} </style>" + "<body>" + '<iframe src="' + this.output("datauristring", options) + '"></iframe>' + "</body></html>";
34633506
var dataURLNewWindow = globalObject.open();
34643507
if (dataURLNewWindow !== null) {
3465-
dataURLNewWindow.document.write(htmlForDataURLNewWindow);
3508+
var initializedDataUrlWindow = initializeNewWindow(dataURLNewWindow);
3509+
var dataUrlFrame = initializedDataUrlWindow.document.createElement("iframe");
3510+
dataUrlFrame.src = this.output("datauristring", options);
3511+
initializedDataUrlWindow.body.appendChild(dataUrlFrame);
34663512
dataURLNewWindow.document.title = options.filename;
34673513
}
34683514
if (dataURLNewWindow || typeof safari === "undefined") return dataURLNewWindow;
@@ -5965,7 +6011,7 @@ jsPDF.API = {
59656011
* @type {string}
59666012
* @memberof jsPDF#
59676013
*/
5968-
jsPDF.version = "4.2.0";
6014+
jsPDF.version = "4.2.1";
59696015

59706016
var jsPDFAPI = jsPDF.API;
59716017
var scaleFactor = 1;
@@ -9514,8 +9560,9 @@ var AcroForm = jsPDF.AcroForm;
95149560
case "freetext":
95159561
rect = "/Rect [" + getHorizontalCoordinateString(anno.bounds.x) + " " + getVerticalCoordinateString(anno.bounds.y) + " " + getHorizontalCoordinateString(anno.bounds.x + anno.bounds.w) + " " + getVerticalCoordinateString(anno.bounds.y + anno.bounds.h) + "] ";
95169562
var color = anno.color || "#000000";
9563+
var defaultStyle = "font: Helvetica,sans-serif 12.0pt; text-align:left; color:#" + color;
95179564
line = "<</Type /Annot /Subtype /" + "FreeText" + " " + rect + "/Contents (" + escape(encryptor(anno.contents)) + ")";
9518-
line += " /DS(font: Helvetica,sans-serif 12.0pt; text-align:left; color:#" + color + ")";
9565+
line += " /DS(" + escape(encryptor(defaultStyle)) + ")";
95199566
line += " /Border [0 0 0]";
95209567
line += " >>";
95219568
this.internal.write(line);

dist/jspdf.es.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/jspdf.es.min.js

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/jspdf.es.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/jspdf.node.js

Lines changed: 99 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/** @license
22
*
33
* jsPDF - PDF Document creation from JavaScript
4-
* Version 4.2.0 Built on 2026-02-19T09:43:09.013Z
4+
* Version 4.2.1 Built on 2026-03-17T11:11:27.057Z
55
* CommitID 00000000
66
*
77
* Copyright (c) 2010-2025 James Hall <james@parall.ax>, https://github.com/MrRio/jsPDF
@@ -3823,6 +3823,47 @@ function jsPDF(options) {
38233823
});
38243824
});
38253825

3826+
var clearDomNode = function(node) {
3827+
while (node.firstChild) {
3828+
node.removeChild(node.firstChild);
3829+
}
3830+
};
3831+
3832+
var initializeNewWindow = function(window) {
3833+
var targetDocument = window.document;
3834+
var html = targetDocument.documentElement;
3835+
var head = targetDocument.head;
3836+
var body = targetDocument.body;
3837+
var style;
3838+
3839+
if (!head) {
3840+
head = targetDocument.createElement("head");
3841+
html.appendChild(head);
3842+
}
3843+
3844+
if (!body) {
3845+
body = targetDocument.createElement("body");
3846+
html.appendChild(body);
3847+
}
3848+
3849+
clearDomNode(head);
3850+
clearDomNode(body);
3851+
3852+
style = targetDocument.createElement("style");
3853+
style.appendChild(
3854+
targetDocument.createTextNode(
3855+
"html, body { padding: 0; margin: 0; } iframe { width: 100%; height: 100%; border: 0;}"
3856+
)
3857+
);
3858+
3859+
head.appendChild(style);
3860+
3861+
return {
3862+
document: targetDocument,
3863+
body: body
3864+
};
3865+
};
3866+
38263867
/**
38273868
* Generates the PDF document.
38283869
*
@@ -3900,7 +3941,7 @@ function jsPDF(options) {
39003941
}
39013942
return (
39023943
"data:application/pdf;filename=" +
3903-
options.filename +
3944+
encodeURIComponent(options.filename) +
39043945
";base64," +
39053946
dataURI
39063947
);
@@ -3910,29 +3951,34 @@ function jsPDF(options) {
39103951
) {
39113952
var pdfObjectUrl =
39123953
"https://cdnjs.cloudflare.com/ajax/libs/pdfobject/2.1.1/pdfobject.min.js";
3913-
var integrity =
3914-
' integrity="sha512-4ze/a9/4jqu+tX9dfOqJYSvyYd5M6qum/3HpCLr+/Jqf0whc37VUbkpNGHR7/8pSnCFw47T1fmIpwBV7UySh3g==" crossorigin="anonymous"';
3954+
var useDefaultPdfObjectUrl = !options.pdfObjectUrl;
39153955

3916-
if (options.pdfObjectUrl) {
3956+
if (!useDefaultPdfObjectUrl) {
39173957
pdfObjectUrl = options.pdfObjectUrl;
3918-
integrity = "";
39193958
}
39203959

3921-
var htmlForNewWindow =
3922-
"<html>" +
3923-
'<style>html, body { padding: 0; margin: 0; } iframe { width: 100%; height: 100%; border: 0;} </style><body><script src="' +
3924-
pdfObjectUrl +
3925-
'"' +
3926-
integrity +
3927-
'></script><script >PDFObject.embed("' +
3928-
this.output("dataurlstring") +
3929-
'", ' +
3930-
JSON.stringify(options) +
3931-
");</script></body></html>";
39323960
var nW = globalObject.open();
39333961

39343962
if (nW !== null) {
3935-
nW.document.write(htmlForNewWindow);
3963+
var initializedPdfObjectWindow = initializeNewWindow(nW);
3964+
var pdfObjectScript = initializedPdfObjectWindow.document.createElement(
3965+
"script"
3966+
);
3967+
var scope = this;
3968+
3969+
pdfObjectScript.src = pdfObjectUrl;
3970+
3971+
if (useDefaultPdfObjectUrl) {
3972+
pdfObjectScript.integrity =
3973+
"sha512-4ze/a9/4jqu+tX9dfOqJYSvyYd5M6qum/3HpCLr+/Jqf0whc37VUbkpNGHR7/8pSnCFw47T1fmIpwBV7UySh3g==";
3974+
pdfObjectScript.crossOrigin = "anonymous";
3975+
}
3976+
3977+
pdfObjectScript.onload = function() {
3978+
nW.PDFObject.embed(scope.output("dataurlstring"), options);
3979+
};
3980+
3981+
initializedPdfObjectWindow.body.appendChild(pdfObjectScript);
39363982
}
39373983
return nW;
39383984
} else {
@@ -3945,30 +3991,33 @@ function jsPDF(options) {
39453991
Object.prototype.toString.call(globalObject) === "[object Window]"
39463992
) {
39473993
var pdfJsUrl = options.pdfJsUrl || "examples/PDF.js/web/viewer.html";
3948-
var htmlForPDFjsNewWindow =
3949-
"<html>" +
3950-
"<style>html, body { padding: 0; margin: 0; } iframe { width: 100%; height: 100%; border: 0;} </style>" +
3951-
'<body><iframe id="pdfViewer" src="' +
3952-
pdfJsUrl +
3953-
"?file=&downloadName=" +
3954-
options.filename +
3955-
'" width="500px" height="400px" />' +
3956-
"</body></html>";
39573994
var PDFjsNewWindow = globalObject.open();
39583995

39593996
if (PDFjsNewWindow !== null) {
3960-
PDFjsNewWindow.document.write(htmlForPDFjsNewWindow);
3997+
var initializedPdfJsWindow = initializeNewWindow(PDFjsNewWindow);
3998+
var pdfViewer = initializedPdfJsWindow.document.createElement(
3999+
"iframe"
4000+
);
4001+
var pdfJsQueryChar = pdfJsUrl.indexOf("?") === -1 ? "?" : "&";
39614002
var scope = this;
3962-
PDFjsNewWindow.document.documentElement.querySelector(
3963-
"#pdfViewer"
3964-
).onload = function() {
4003+
4004+
pdfViewer.id = "pdfViewer";
4005+
pdfViewer.width = "500px";
4006+
pdfViewer.height = "400px";
4007+
pdfViewer.src =
4008+
pdfJsUrl +
4009+
pdfJsQueryChar +
4010+
"file=&downloadName=" +
4011+
encodeURIComponent(options.filename);
4012+
4013+
pdfViewer.onload = function() {
39654014
PDFjsNewWindow.document.title = options.filename;
3966-
PDFjsNewWindow.document.documentElement
3967-
.querySelector("#pdfViewer")
3968-
.contentWindow.PDFViewerApplication.open(
3969-
scope.output("bloburl")
3970-
);
4015+
pdfViewer.contentWindow.PDFViewerApplication.open(
4016+
scope.output("bloburl")
4017+
);
39714018
};
4019+
4020+
initializedPdfJsWindow.body.appendChild(pdfViewer);
39724021
}
39734022
return PDFjsNewWindow;
39744023
} else {
@@ -3980,17 +4029,17 @@ function jsPDF(options) {
39804029
if (
39814030
Object.prototype.toString.call(globalObject) === "[object Window]"
39824031
) {
3983-
var htmlForDataURLNewWindow =
3984-
"<html>" +
3985-
"<style>html, body { padding: 0; margin: 0; } iframe { width: 100%; height: 100%; border: 0;} </style>" +
3986-
"<body>" +
3987-
'<iframe src="' +
3988-
this.output("datauristring", options) +
3989-
'"></iframe>' +
3990-
"</body></html>";
39914032
var dataURLNewWindow = globalObject.open();
39924033
if (dataURLNewWindow !== null) {
3993-
dataURLNewWindow.document.write(htmlForDataURLNewWindow);
4034+
var initializedDataUrlWindow = initializeNewWindow(
4035+
dataURLNewWindow
4036+
);
4037+
var dataUrlFrame = initializedDataUrlWindow.document.createElement(
4038+
"iframe"
4039+
);
4040+
4041+
dataUrlFrame.src = this.output("datauristring", options);
4042+
initializedDataUrlWindow.body.appendChild(dataUrlFrame);
39944043
dataURLNewWindow.document.title = options.filename;
39954044
}
39964045
if (dataURLNewWindow || typeof safari === "undefined")
@@ -6902,7 +6951,7 @@ jsPDF.API = {
69026951
* @type {string}
69036952
* @memberof jsPDF#
69046953
*/
6905-
jsPDF.version = "4.2.0";
6954+
jsPDF.version = "4.2.1";
69066955

69076956
/* global jsPDF */
69086957

@@ -11226,6 +11275,9 @@ var AcroForm = jsPDF.AcroForm;
1122611275
getVerticalCoordinateString(anno.bounds.y + anno.bounds.h) +
1122711276
"] ";
1122811277
var color = anno.color || "#000000";
11278+
var defaultStyle =
11279+
"font: Helvetica,sans-serif 12.0pt; text-align:left; color:#" +
11280+
color;
1122911281
line =
1123011282
"<</Type /Annot /Subtype /" +
1123111283
"FreeText" +
@@ -11234,10 +11286,7 @@ var AcroForm = jsPDF.AcroForm;
1123411286
"/Contents (" +
1123511287
escape(encryptor(anno.contents)) +
1123611288
")";
11237-
line +=
11238-
" /DS(font: Helvetica,sans-serif 12.0pt; text-align:left; color:#" +
11239-
color +
11240-
")";
11289+
line += " /DS(" + escape(encryptor(defaultStyle)) + ")";
1124111290
line += " /Border [0 0 0]";
1124211291
line += " >>";
1124311292
this.internal.write(line);

dist/jspdf.node.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/jspdf.node.min.js

Lines changed: 23 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/jspdf.node.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)