Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AnalyzePlatypus/55d806caa739ba6c2b27ede752fa3c9c to your computer and use it in GitHub Desktop.
Save AnalyzePlatypus/55d806caa739ba6c2b27ede752fa3c9c to your computer and use it in GitHub Desktop.
jsPDF helper function: Convert points to other units
function convertPointsToUnit(points, unit) {
// Unit table from https://github.com/MrRio/jsPDF/blob/ddbfc0f0250ca908f8061a72fa057116b7613e78/jspdf.js#L791
var multiplier;
switch(unit) {
case 'pt': multiplier = 1; break;
case 'mm': multiplier = 72 / 25.4; break;
case 'cm': multiplier = 72 / 2.54; break;
case 'in': multiplier = 72; break;
case 'px': multiplier = 96 / 72; break;
case 'pc': multiplier = 12; break;
case 'em': multiplier = 12; break;
case 'ex': multiplier = 6;
default:
throw ('Invalid unit: ' + unit);
}
return points * multiplier;
}
@lxmfly123
Copy link

你这写反了吧,应该是 convertUnitToPoints 吧。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment