#29758

An “optimum” criteria differs depending on a use case. If you have an HTML document with a hardcoded table width=1000, by any htmlWidth less than 1000 the resulting document layout will be cut right side.

Let’s call the desired optimum is when 1pt defined in HTML corresponds to 1pt in PDF and in printed output. It can be useful if you need a correct font size (given in pt) conversion.

pageFormat is measured in physical units (pt)
pageInsets are also in pt
htmlWidth is in screen pixels
px/pt = 1.35
A4 width is 595pt

(pageFormat.width – pageInsets.left – pageInsets.right) / htmlWidth = 1/1.35
htmlWidth = 1.35 * (pageFormat.width – pageInsets.left – pageInsets.right)
for A4:
htmlWidth = 1.35 * (595 – pageInsets.left – pageInsets.right)

If the desired optimum is 1px defined in HTML corresponds to 1pt in PDF and in printed output.

htmlWidth = 595 – pageInsets.left – pageInsets.right

For landscape A4 orientation replace 595 with 842