We're writing our own web app and we need the user to have a (fairly) accurate visualisatio开发者_开发百科n of their printed documents on-screen. I'm using the centimetre unit in CSS to try and replicate an A4 page.
I need to work out the actual pixel height assigned to the following:
max-height: 27cm;
Is this possible in javaScript? I need the pixel height because I need to compare the offsetHeight to the max-height.
Well, due to screens of differing size, resolution, and PPI, it wouldn't really be possible to display a real life sized view of a page that is consistent across screens. Not unless you could find the size of the pixels themselves, but I do not believe that is possible via JS.
Short of asking the user to measure something with a known number of pixels and then type the matching number of cm or in — no.
I'm not aware of any API that exposes the system DPI to JavaScript, and most systems don't have their DPI correctly calibrated anyway.
精彩评论