Skip to content

Instantly share code, notes, and snippets.

@flier268
Created June 5, 2018 02:05
Show Gist options
  • Save flier268/07183c6e0a695eab6197447249bf9a7b to your computer and use it in GitHub Desktop.
Save flier268/07183c6e0a695eab6197447249bf9a7b to your computer and use it in GitHub Desktop.
Get real font-size(Wkhtmltox)
<html id="html">
<body>
<div style="width:100%" id="ruler"></div>
<div style="width:50%">
<p style="font-size:1rem;">This is 1 rem</p>
</div>
<script>
function w3_getStyleValue(elmnt,style) {
if (window.getComputedStyle) {
return window.getComputedStyle(elmnt,null).getPropertyValue(style);
} else {
return elmnt.currentStyle[style];
}
}
var t;
var width, height;
width = Number(w3_getStyleValue(document.getElementById("ruler"), "width").replace("px", "")).toFixed();
document.getElementById("html").style.fontSize=((595/width)*12)+"pt";
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment