Skip to content

Commit 5734d5e

Browse files
authored
fix: Using canvas as a direct source (#701)
1 parent 4c55448 commit 5734d5e

11 files changed

+8
-3
lines changed

src/worker.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Worker.prototype.from = function from(src, type) {
6161
function getType(src) {
6262
switch (objType(src)) {
6363
case 'string': return 'string';
64-
case 'element': return src.nodeName.toLowerCase === 'canvas' ? 'canvas' : 'element';
64+
case 'element': return src.nodeName.toLowerCase && src.nodeName.toLowerCase() === 'canvas' ? 'canvas' : 'element';
6565
default: return 'unknown';
6666
}
6767
}
@@ -168,7 +168,8 @@ Worker.prototype.toImg = function toImg() {
168168
Worker.prototype.toPdf = function toPdf() {
169169
// Set up function prerequisites.
170170
var prereqs = [
171-
function checkCanvas() { return this.prop.canvas || this.toCanvas(); }
171+
function checkCanvas() { return this.prop.canvas || this.toCanvas(); },
172+
function checkPageSize() { return this.prop.pageSize || this.setPageSize(); }
172173
];
173174

174175
// Fulfill prereqs then create the image.

test/reference/snapshot/all-tags.pdf

561 KB
Binary file not shown.
4.88 KB
Binary file not shown.
69.3 KB
Binary file not shown.
1.03 MB
Binary file not shown.
1.04 MB
Binary file not shown.
Binary file not shown.
370 KB
Binary file not shown.
321 KB
Binary file not shown.
370 KB
Binary file not shown.

test/snapshot.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ describe('snapshot', () => {
3131
runner: window => defaultCondition(window, { margin: 1, jsPDF: { unit: 'in' } }),
3232
name: file => `${file}_margin.pdf`,
3333
},
34+
selectCanvas: {
35+
runner: window => defaultCondition(window, {}, window.document.getElementById('canvas')),
36+
name: file => `${file}_canvas.pdf`,
37+
},
3438
selectMainId: {
3539
runner: window => defaultCondition(window, {}, window.document.getElementById('main')),
3640
name: file => `${file}.pdf`,
@@ -56,7 +60,7 @@ describe('snapshot', () => {
5660
const filesToTest = {
5761
'blank': [ 'default' ],
5862
'lorem-ipsum': [ 'default', 'legacy', 'margin' ],
59-
'all-tags': [ 'default' ],
63+
'all-tags': [ 'default', 'selectCanvas' ],
6064
'css-selectors': [ 'selectMainId' ],
6165
'pagebreaks': [ 'pagebreakLegacy', 'pagebreakCss', 'pagebreakAvoidAll', 'pagebreakSpecify' ],
6266
};

0 commit comments

Comments
 (0)