Darshan Darshi
Darshan Darshi

Reputation: 21

How to define the scale and letter size on a print preview in Microsoft Edge or Internet Explorer through Java or JavaScript

I have defined the Print CSS through media print in my CSS file. In Chrome and Firefox, the same is getting applied. Whereas in Internet Explorer and Edge Browser, I need to manually select the scale to 75% and letter size to 8.5" * 11" and then print. Is there a way through Java (As my backend runs on Play Framework) or JavaScript to define it in the first place? Thanks in advance

Upvotes: 2

Views: 1241

Answers (1)

scunliffe
scunliffe

Reputation: 63588

Some browsers (e.g. Chrome) do support the ability to specify "hints" via CSS to the browser in terms of printing preferences.

<style>
  @media print{
    @page{
      margin:1in;/* Default margin (for page content) */
      /*margin:0in; Sets margin to zero AND hides all the page #/date/URL fluff */
      size:landscape;/* Default to Landscape */
    }
  }
</style>

Sadly this is not an official standard yet and is considered experimental: https://developer.mozilla.org/en-US/docs/Web/CSS/@page/size

I'd certainly love all browsers to pick this up as it would be great to be able to provide sensible printing defaults to user agents.

Current support for Landscape & Margin:

  • Chrome
  • Vivaldi (based on Chrome)
  • Brave (based on Chrome)(although there is currently no print preview)
  • Opera (based on Chrome)

Current support for Margin only:

  • Firefox

Test Page: https://css-printing-hints.glitch.me/

Upvotes: 1

Related Questions