Skip to content

Commit 283f8c4

Browse files
committed
Allow for other units
Provide values for px, pc, em, ex and utilize switch for divisor determination.
1 parent 27df11e commit 283f8c4

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

jspdf.js

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -788,16 +788,33 @@ var jsPDF = (function(global) {
788788
// @TODO: Add different output options
789789
});
790790

791-
if (unit === 'pt') {
792-
k = 1;
793-
} else if (unit === 'mm') {
794-
k = 72 / 25.4;
795-
} else if (unit === 'cm') {
796-
k = 72 / 2.54;
797-
} else if (unit === 'in') {
798-
k = 72;
799-
} else {
800-
throw('Invalid unit: ' + unit);
791+
switch (unit) {
792+
case 'pt':
793+
k = 1;
794+
break;
795+
case 'mm':
796+
k = 72 / 25.4;
797+
break;
798+
case 'cm':
799+
k = 72 / 2.54;
800+
break;
801+
case 'in':
802+
k = 72;
803+
break;
804+
case 'px':
805+
k = 96 / 72;
806+
break;
807+
case 'pc':
808+
k = 12;
809+
break;
810+
case 'em':
811+
k = 12;
812+
break;
813+
case 'ex':
814+
k = 6;
815+
break;
816+
default:
817+
throw ('Invalid unit: ' + unit);
801818
}
802819

803820
// Dimensions are stored as user units and converted to points on output

0 commit comments

Comments
 (0)