1

I need to print a web page on regular A4 page.

The print result should be exactly 20cm x 20cm (no matter it's position on paper).

I have this html page:

body {
  -webkit-print-color-adjust: exact;
  height: 20cm;
  width: 20cm;
  margin: 0;
  padding: 0
}

img {
  height: 20cm;
  width: 20cm;
  position: absolute;
  top: 0;
  left: 0;
}

h1 {
  font-size: 0.9cm;
  position: relative;
  top: 1cm;
  text-align: center;
  width: 70%;
  margin: 0 auto;
  color: #ffde00;
}

@media print {
  body {
    height: 20cm;
    width: 20cm;
  }
}
<img src="background.png">
<h1>My Example Text</h1>

When I am printing this page (on a regular lasterJet A4 printer) I am getting about 18.9cm result on the paper.

How can I make it exactly 20cm ?

tgogos
  • 23,218
  • 20
  • 96
  • 128
Tal Levi
  • 321
  • 6
  • 19

1 Answers1

0

To set the print area you can use @media print an example:

/* style sheet for “letter” printing */
@media print and (width: 1.5in) and (height: 1in) {
@page {
margin: 1in;
}
}
FabricioG
  • 3,107
  • 6
  • 35
  • 74