html - Put as many elements as possible in each page print -
i trying print categories, each category contains unknown number of elements.
every page needs:
- header , footer.
- to include categories as possible
i try "position:fixed" header , footer, , "page-break-inside: avoid" category container. first page fine, in others categories start top of page, , behind header.
the question :
there way in media print?
if not, there way render page looks wont, , print it?
this example:
<style> @media print { .category { page-break-inside: avoid; padding: 10px; } .page { padding-top: 20px; } } </style> <body> <h1 style="position:fixed">this text hide category in second page </h1> <div class="page"> <div class="category"> category 1<br/>item<br/>item<br/>item<br/> </div> <div class="category"> category 2<br/>item<br/>item<br/>item<br/>item<br/>item<br/> </div> <div class="category"> category 3<br/>item<br/>item </div> <!--and on --> </div> </body>
finally calculate div height each category, , add page-break if needed.
for (let cat of menu.categories) { mywindow.document.write('<div id="' + cat._id + '" class="content">'); // write category mywindow.document.write('</div>'); //end of content var currentpagedivheight = mywindow.document.getelementbyid('a4').clientheight - (1000 * pagenamber); console.log('currentpagedivheight:' + currentpagedivheight) if ( currentpagedivheight > 750) { pagenamber++; mywindow.document.getelementbyid(cat._id).style.setproperty("page-break-before", 'always'); mywindow.document.getelementbyid(cat._id).style.setproperty("padding-top", '5cm'); } }
Comments
Post a Comment