Reputation: 2631
I am generating reports in HTML formats, and want to print them automatically using Qt (qt has a webkit based browser, and one can render its contents to a PDF file). I want to position the elements of the report depending on the target page size. For that i need to access the size of the paper (preferably in pixels).
Since i am using webkit, it has all the latest html5 and css3 features.
is there some api available to access printed page properties inside javascript. for example, would be nice to write: window.print_paper.width or window.print_paper.height
Thank you in advance
Upvotes: 1
Views: 2877
Reputation: 5105
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).
Upvotes: 2
Reputation: 12561
You could get the contents size via QWebFrame::contentsSize() and the make it available to the JavaScript world, e.g. using QWebFrame::addToJavaScriptWindowObject().
Upvotes: 0
Reputation: 31715
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.
Upvotes: 3
Reputation:
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
Upvotes: 2