0

I need to somehow calculate how many a4 papers will a div on my website contain. I know that a4 paper size in pixels changes based on a screens dpi. I'm looking for a way to calculate the users screen dpi then convert it to a4 page measures in pixels and divide my div's height by that amount in order to simulate the page count using javascript or Jquery. Would that be a good way to do it or is there an alternative? And how can I know a given screens dpi (whatever it may be) and convert it to pixels?

durian
  • 510
  • 1
  • 7
  • 24

1 Answers1

0

You can calculate the user's screen DPI using:

<div id='testdiv' style='height: 1in; left: -100%; position: absolute; top: -100%; width: 1in;'></div>

and

dpi_x = document.getElementById('testdiv').offsetWidth;
dpi_y = document.getElementById('testdiv').offsetHeight;

console.log("dpi_x: "+dpi_x+", dpi_y:"+dpi_y);

REFERENCE

Additionally, you might want to give this a read.

Community
  • 1
  • 1
Anubhav
  • 7,138
  • 5
  • 21
  • 33