RIRedinPA Posted September 23, 2009 Share Posted September 23, 2009 I folks. I am trying to send a document to the printer via javascript and use css to insert page breaks but I am having no luck with it. I keep getting just one page printed out with no breaks, it just bleeds off the bottom of the page where the break should be. Here's my CSS set up: body { margin: 0; } #printpreview { position: relative; margin: 0 auto; top: 150px; height: 540px; width: 420px; background-color: #eee; text-align: center; } #printpreview img { position: relative; top: 10px; } #printpreview a { font-size: .8em; font-weight: 500; } @media print { .pagebreak { page-break-before: always; } } Here's the javascript code: function printokay(pages) { var printcode = ""; var pagearray = pages.split(","); for (var x=0; x<pagearray.length; x++) { var imgnum = leftTrim(pagearray[x]); if (x+1 < pagearray.length) { printcode += "<div id=\"page_" + imgnum + "\" style=\"width: 600px; height: 800px; border: 1px solid black;\" class=\"pagebreak\"><img src=\"http://macdev2.xxx.com/printtest/images/ot/090109/adv_ot_pg" + imgnum + ".jpg\" height=\"100%\"></div><a name=\"break2\" class=\"pagebreak\"><p>"; } else { printcode += "<div id=\"page_" + imgnum + "\" style=\"width: 600px; height: 800px; border: 1px solid black;\" class=\"pagebreak\"><img src=\"http://macdev2.xxx.com/printtest/images/ot/090109/adv_ot_pg" + imgnum + ".jpg\" height=\"100%\"></div><p>"; } } document.getElementById('printwin').style.left = "0px"; document.getElementById('printwin').innerHTML = printcode; window.print(); } Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/175254-printing-multiple-pages-with-css/ Share on other sites More sharing options...
TheFilmGod Posted September 24, 2009 Share Posted September 24, 2009 Did you declare @media screen in the beginning. I never did it like this. Typically you would use a separate stylesheet for each media type. I recommend you do the same. Quote Link to comment https://forums.phpfreaks.com/topic/175254-printing-multiple-pages-with-css/#findComment-923930 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.