How to find out the dimensionality of print paper in javascript

这一生的挚爱 提交于 2019-12-06 16:23:11

What you're asking for is backwards from the standards-track @page spec. What CSS3 paged media (@page) allows you to do is specify an orientation and page size that your document should be printed on - not query your system for the currently selected orientation and page size. Even the CSS3 media query stuff won't allow you to do this, to the best of my knowledge.

it's not possible. Javascript can't access to your printer to detect paper size. You can't even use pixel measurement because it's relative to the screen so you have to use other units like pt, inches, centimeters

Oliver Bock

Use the Accept-Language request header to determine if the user is in a Letter-using locale, otherwise assume A4. Assume portrait if that suits your users. Then sniff the browser to guess at the margins (IE9 = =19.05mm, FF5 = 12.7mm, IE6 = 7.5mm, Chrome = ~10mm).

You could get the contents size via QWebFrame::contentsSize() and the make it available to the JavaScript world, e.g. using QWebFrame::addToJavaScriptWindowObject().

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!