/// <summary> /// fit image 100% considering margin /// </summary> public static Picture ImageFit(this DocX docx, string pathfilename, double factor = 1.0) { var page_width_in = docx.PointsToMeasure((int)docx.PageWidth).Value; var page_width_avail_in = page_width_in - docx.PointsToMeasure((int)docx.MarginLeft).Value - docx.PointsToMeasure((int)docx.MarginRight).Value; factor = factor * (page_width_avail_in / page_width_in); var img = docx.AddImage(pathfilename); var res = img.CreatePicture(); var ratio_w_h = (double)res.Width / res.Height; res.SetSizeInches(page_width_avail_in, page_width_avail_in / ratio_w_h); return(res); }