1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.Load(pathFileToLoad);
HtmlNodeCollection images = doc.DocumentNode.SelectNodes("//img");
if (images != null)
{
foreach (HtmlNode image in images)
{
string stylImg = image.GetAttributeValue("style", "");
if (!string.IsNullOrEmpty(stylImg))
{
stylImg = Regex.Replace(stylImg, "(width:\\d+\\.?\\d*)", "$1px");
stylImg = Regex.Replace(stylImg, "(height:\\d+\\.?\\d*)", "$1px");
image.SetAttributeValue("style", stylImg);
}
}
}
doc.Save(pathFileToSave); |
Partager