Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print to hardcopy using javascript - landscape mode

Print a web page in landscape mode using javascript. While printing, I want to:

  1. Set margins
  2. Landscape mode
like image 849
LIGHT Avatar asked Dec 28 '22 12:12

LIGHT


1 Answers

You can mark up the size and margins of a printed page with an @page CSS rule:

/* In CSS, not JavaScript */
@page {
  size: A4 landscape;
  margin: 42pt 12pt;
}

@media print {
  /* Define print-specific styles here, for example toning down the decoration
     of hyperlinks and removing the navigation. */
  a {color: inherit !important; text-decoration: none !important;}
  nav {display: none;}
}

However, browser support is spotty - aside from prince XML, only IE8+ and Opera support it. If you want precise cross-browser control over printing, consider a (typically server-side) PDF output mechanism.

like image 138
phihag Avatar answered Jan 12 '23 19:01

phihag