Skip to content

Commit

Permalink
Update jspdf
Browse files Browse the repository at this point in the history
  • Loading branch information
linev committed Oct 9, 2024
1 parent 1edd8cf commit 1afb54e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 122 deletions.
1 change: 1 addition & 0 deletions libs/jsPDF/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ https://github.com/linev/jsPDF/commits/jsroot/
4. Comment out svg.js, html.js, fileloading.js - not used with svg2pdf
5. Remove API.save
6. Remove 'fflate' from externals - include into build
7. Remove several outpus - code with </script> confuses browser when loaded directly

## How to build

Expand Down
44 changes: 22 additions & 22 deletions libs/jspdf.mjs

Large diffs are not rendered by default.

100 changes: 0 additions & 100 deletions modules/base/jspdf.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3826,9 +3826,6 @@ function jsPDF(options) {
* 'bloburi'/'bloburl' -> (string)<br/>
* 'datauristring'/'dataurlstring' -> (string)<br/>
* 'datauri'/'dataurl' -> (undefined) -> change location to generated datauristring/dataurlstring<br/>
* 'dataurlnewwindow' -> (window | null | undefined) throws error if global isn't a window object(node)<br/>
* 'pdfobjectnewwindow' -> (window | null) throws error if global isn't a window object(node)<br/>
* 'pdfjsnewwindow' -> (wind | null)
* @param {Object|string} options An object providing some additional signalling to PDF generator.<br/>
* Possible options are 'filename'.<br/>
* A string can be passed instead of {filename:string} and defaults to 'generated.pdf'
Expand Down Expand Up @@ -3895,103 +3892,6 @@ function jsPDF(options) {
";base64," +
dataURI
);
case "pdfobjectnewwindow":
if (
Object.prototype.toString.call(globalObject) === "[object Window]"
) {
var pdfObjectUrl =
"https://cdnjs.cloudflare.com/ajax/libs/pdfobject/2.1.1/pdfobject.min.js";
var integrity =
' integrity="sha512-4ze/a9/4jqu+tX9dfOqJYSvyYd5M6qum/3HpCLr+/Jqf0whc37VUbkpNGHR7/8pSnCFw47T1fmIpwBV7UySh3g==" crossorigin="anonymous"';

if (options.pdfObjectUrl) {
pdfObjectUrl = options.pdfObjectUrl;
integrity = "";
}

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>";
var nW = globalObject.open();

if (nW !== null) {
nW.document.write(htmlForNewWindow);
}
return nW;
} else {
throw new Error(
"The option pdfobjectnewwindow just works in a browser-environment."
);
}
case "pdfjsnewwindow":
if (
Object.prototype.toString.call(globalObject) === "[object Window]"
) {
var pdfJsUrl = options.pdfJsUrl || "examples/PDF.js/web/viewer.html";
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>";
var PDFjsNewWindow = globalObject.open();

if (PDFjsNewWindow !== null) {
PDFjsNewWindow.document.write(htmlForPDFjsNewWindow);
var scope = this;
PDFjsNewWindow.document.documentElement.querySelector(
"#pdfViewer"
).onload = function() {
PDFjsNewWindow.document.title = options.filename;
PDFjsNewWindow.document.documentElement
.querySelector("#pdfViewer")
.contentWindow.PDFViewerApplication.open(
scope.output("bloburl")
);
};
}
return PDFjsNewWindow;
} else {
throw new Error(
"The option pdfjsnewwindow just works in a browser-environment."
);
}
case "dataurlnewwindow":
if (
Object.prototype.toString.call(globalObject) === "[object Window]"
) {
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>";
var dataURLNewWindow = globalObject.open();
if (dataURLNewWindow !== null) {
dataURLNewWindow.document.write(htmlForDataURLNewWindow);
dataURLNewWindow.document.title = options.filename;
}
if (dataURLNewWindow || typeof safari === "undefined")
return dataURLNewWindow;
} else {
throw new Error(
"The option dataurlnewwindow just works in a browser-environment."
);
}
break;
case "datauri":
case "dataurl":
return (globalObject.document.location.href = this.output(
Expand Down

0 comments on commit 1afb54e

Please sign in to comment.