private static bool ConvertStyleFromPxToPercent(string stylename, double pageWidthMm, double multiplier, ref string imgStyle)
{
var match = new Regex("(.*" + stylename + ":\\s*)(\\d+)px(.*)").Match(imgStyle);
if (!match.Success)
return true;
var widthPx = int.Parse(match.Groups[2].Value);
var widthInch = widthPx/96.0; // in print a CSS px is exactly 1/96 inch
const int marginBoxMarginMm = 40; // see basePage.less SetMarginBox.
var marginBoxWidthInch = (pageWidthMm - marginBoxMarginMm)/mmPerInch;
var parentBoxWidthInch = marginBoxWidthInch*multiplier; // parent box is smaller by net effect of parents with %width styles
// 1/10 percent is close enough and more readable/testable than arbitrary precision; make a string with one decimal
var newWidth = (Math.Round(widthInch/parentBoxWidthInch*1000)/10).ToString("F1");
imgStyle = match.Groups[1] + newWidth + "%" + match.Groups[3];
return false;
}