Skip to content

Commit

Permalink
change to jspdf
Browse files Browse the repository at this point in the history
  • Loading branch information
JannikStreek committed Jan 4, 2024
1 parent f920053 commit ce02435
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/node/utils/Minify.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ const LIBRARY_WHITELIST = [
'tinycon',
'underscore',
'unorm',
'jspdf',
'dompurify',
'html2canvas'
];

// What follows is a terrible hack to avoid loop-back within the server.
Expand Down
157 changes: 157 additions & 0 deletions src/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@
"ueberdb2": "^4.2.45",
"underscore": "1.13.6",
"unorm": "1.6.0",
"wtfnode": "^0.9.1"
"wtfnode": "^0.9.1",
"jspdf": "2.5.1",
"dompurify": "2.4.7",
"html2canvas": "1.4.1"
},
"bin": {
"etherpad": "node/server.js",
Expand Down
15 changes: 11 additions & 4 deletions src/static/js/pad_impexp.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
* limitations under the License.
*/

const { jsPDF } = require("jspdf/dist/jspdf.umd.min.js");
window.DOMPurify = require("dompurify/dist/purify.min.js");
window.html2canvas = require("html2canvas/dist/html2canvas.min.js");

const padimpexp = (() => {
let pad;

Expand Down Expand Up @@ -124,10 +128,13 @@ const padimpexp = (() => {
fetch(url).then((response) => {
return response.text()
}).then((html) => {
const printWindow = window.open('', '', 'height=400,width=800');
printWindow.document.write(html);
printWindow.document.close();
printWindow.print();
const doc = new jsPDF('p', 'px', 'a4');
const wrappedHTML = `<div style="font-size:8px; width:430px;">${html}</div>`
doc.html(wrappedHTML, {
callback: (doc) => doc.output("dataurlnewwindow"),
x: 15,
y: 15
})
})
}

Expand Down

0 comments on commit ce02435

Please sign in to comment.