Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format a HTML document into multiple A4 size sections

Tags:

html

css

printing

This is my current problem.

I want to generate a HTML page, which contains about 40 coupons. Each coupon must be with one A4 sized section.

So, if I were to print the HTML document, I would like each printed page to contain 1 coupon.

Ideas on how I could accomplish this ?

like image 575
Prakash Raman Avatar asked Mar 15 '12 11:03

Prakash Raman


People also ask

How do I make my html page fixed size?

However, with no width value provided for the HTML element, setting the width of the body element to 100% results in full page width. This can be counterintuitive and confusing. For a responsive full page height, set the body element min-height to 100vh.


2 Answers

The following CSS should achieve what you need, subistitute the class name for whatever is appropriate for your DOM structure

 @media print {
  .coupon-class 
  {
   page-break-after:always;
  }
 }

This will always insert a page break after the element you can also use page-break-before to achieve a page break before an element.

like image 134
Simon West Avatar answered Sep 23 '22 20:09

Simon West


You'll never get a very precise solution using HTML, as every browser decides its way of printing HTML is best and adds all sorts of headers and footers that change the page dimensions and how the clients printer actually prints it.

You would be better off generating a PDF of your coupons which you can easily do with PHP extensions.

like image 32
deed02392 Avatar answered Sep 22 '22 20:09

deed02392