Page has a rule that overrides user-set margins:
@media print { @page { margin-top: 0.2in; margin-bottom: 0.2in; margin-left: 0.2in; margin-right: 0.2in; } }
This script can override the tiny margins specified in @page, but it would be better to just disregard those margins if they are smaller than what the user specified:
// 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/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'; } } } } } } }