Default for A4 will be dependant of getting metric sheet ratios correct, and sadly there are too many wrong answers.
default as px will naturally be rounded off in applications as px should be integers thus unreal
A4 as pixels based on a (incorrect assumption there are a fixed number of 96 per inch)
width: 793.701px;
height: 1122.52px;
QT Web Kit uses 160dpi
thus it will work with
body {
border: 0;
margin: 0;
padding: 0;
width: 992.126px;
height: 1403.15px;
}
.myDiv {
border: 5px outset red;
background-color: lightblue;
text-align: center;
height: 1393.15px;
}
Ideally the Media when printing should also be set
<style>
@media print {
@page { size: 210mm,297mm; }
}
body {
The big issue is the use of WebKit scale by default
--enable-smart-shrinking
Enable the intelligent shrinking strategy
used by WebKit that makes the pixel/dpi
ratio non-constant (default)
This means that for A4 wide @100% we need a different value
and from trial and error you may find this works
body {
border: 0;
margin: 0;
padding: 0;
}
.myDiv {
background-color: red;
text-align: center;
width: 100%;
height: 1052.9pt;
}
So for HTML graphics like these where 96 is the norm we need to add an over-ride --disable-smart-shrinking
And the correct ratio and scale will be used
wkhtmltopdf.exe -B 0 -T 0 -L 0 -R 0 -s A4 --disable-smart-shrinking red.htm red.pdf
And the result should be perfect.
A Secondary problem is different browsers use different rounding off strategy when determining PDF units, thus the value for FireFox may need a small adjustment for Chromium! and visa versa!
page-size A4
and 210mm x 297mm... it's intersting to know, though, that Letter seems to work properly. – Fruiterer--disable-smart-shrinking
flag, see my answer – Kraft