Created
December 9, 2018 21:19
-
-
Save jscher2000/3fd7af422ab57b6b5c63ffb22824b623 to your computer and use it in GitHub Desktop.
Override @page{margin} rules with reasonable values
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Override @page{margin} rule if found | |
var docSS = document.styleSheets, ss, ess; | |
for (var i=0; i<docSS.length; i++){ | |
if (!docSS[i].disabled){ | |
// check content of style sheet for @page (type 6 style sheet) | |
// https://developer.mozilla.org/en-US/docs/Web/API/CSSRule#Type_constants | |
ss = docSS[i]; | |
for (var j=0; j<ss.cssRules.length; j++){ | |
if (ss.cssRules[j].type == 6){ // Page sheet | |
if (ss.cssRules[j].cssText.indexOf('margin') > -1){ | |
// Try overriding to 0.5in top/bottom, 0.25in left/right | |
ss.cssRules[j].style.margin = '1.27cm 0.64cm'; | |
} | |
} else if (ss.cssRules[j].type == 4){ // Print Media sheet | |
// Check for any embedded Page sheet inside | |
ess = ss.cssRules[j]; | |
for (var k=0; k<ess.cssRules.length; k++){ | |
if (ess.cssRules[k].type == 6){ | |
if (ess.cssRules[k].cssText.indexOf('margin') > -1){ | |
// Try overriding to 0.5in top/bottom, 0.25in left/right | |
ess.cssRules[k].style.margin = '1.27cm 0.64cm'; | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment