/// <summary>
/// 在指定标签后插入图片
/// </summary>
/// <param name="doc"></param>
/// <param name="bm"></param>
/// <param name="pic"></param>
/// <param name="width"></param>
/// <param name="height"></param>
public static void ModifyPicture(Document doc, string bm, string pic,double width=40)
{
try
{
//判断标签和图片是否存在
if (BookMarkIsExist(doc, bm) is true && File.Exists(pic))
{
//获取标签
Bookmark bookmark = doc.Range.Bookmarks[bm];
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToBookmark(bm);
//获取当前所在的段落
Paragraph paragraph = builder.CurrentParagraph;
//Shape shape= builder.InsertImage(pic, RelativeHorizontalPosition.Character, paragraph.GetText().Length, RelativeVerticalPosition.Paragraph, 1, width, height, WrapType.None);
Shape shape = builder.InsertImage(pic);
double w = shape.Width;
shape.Width = width;
shape.Height = (width * 1.0 / w) * shape.Height;
shape.RelativeVerticalPosition = RelativeVerticalPosition.Paragraph;
shape.RelativeHorizontalPosition = RelativeHorizontalPosition.Character;
shape.Left = paragraph.GetText().Length;
shape.WrapType = WrapType.None;
}
}
catch (Exception)
{
throw;
}
}