0

I need to set a layout to be printed using paper of half letter size (215mm height and 139mm width). I have tested many css parameters such as

@page {
  size: 139mm 215mm;
  margin: 0;
}

@media print {
  @page {
    size: 139mm 215mm;
  }
}

html {
  width: 139mm;
  height: 215mm;
  margin: 0;
}

body {
  width: 139mm;
  height: 215mm;
  margin: 0;
}
<body>
  <div style="height: 215mm; width: 139mm; border:solid grey 1px;">
    <!-- My content -->
    ...
  </div>
</body>

But when I print using Control+P, I always get a Legal vertical size page.

How can I set this custom size to be printed in any browser?

Jos van Weesel
  • 2,128
  • 2
  • 12
  • 27
Alex Lord Mordor
  • 2,890
  • 7
  • 27
  • 47

1 Answers1

0

Beside defining size you also need to define height and width for @page. I updated your code and placed it below, I hope that solves your problem.

Key part:

@page {
  size: 139mm 215mm;
  height: 215mm;
  width: 139mm;
  margin: 0;
}

Snippet:

window.print();
@page {
  size: 139mm 215mm;
  height: 215mm;
  width: 139mm;
  margin: 0;
}

html {
  width: 139mm;
  height: 215mm;
  margin: 0;
}

body {
  width: 139mm;
  height: 215mm;
  margin: 0;
}
<body>
  <div style="height: 215mm; width: 139mm; border:solid grey 1px;">
    <!-- My content -->
    ...
  </div>
</body>

Updated JSFiddle

Andrzej Ziółek
  • 2,241
  • 1
  • 13
  • 21