需求:如何在doc文档,指定页数中插入图片呢,例如:我想在第1页、3页、5页....奇数页中,指定位置插入想要的图片
参考的code里,是以节来操作,拿到一个任意文档,默认只有一节,仅能控制图片在第一页的位置,如何能够放到想要页数的位置呢,求教!
string input = @"Bookmark.docx";
Document doc = new Document();
doc.LoadFromFile(input);
BookmarksNavigator bn = new BookmarksNavigator(doc);
bn.MoveToBookmark("Image", true, false);
Section section0 = doc.AddSection();
Paragraph paragraph = section0.AddParagraph();
Image image = Image.FromFile(@"E-iceblueLogo.png");
DocPicture picture = paragraph.AppendPicture(image);
bn.InsertParagraph(paragraph);
doc.Sections.Remove(section0);
string output = "InsertImageAtBookmark.docx";
doc.SaveToFile(output, FileFormat.Docx);
string input = @"Bookmark.docx";
Document doc = new Document();
doc.LoadFromFile(input);
Image image = Image.FromFile(@"E-iceblueLogo.png");
TextSelection[] selections = doc.FindAllString("Word", true, false);
int index = 0;
TextRange range = null;
foreach (TextSelection selection in selections)
{
range = selection.GetAsOneRange();
index = range.OwnerParagraph.ChildObjects.IndexOf(range);
range.OwnerParagraph.AppendPicture(image);
}
doc.SaveToFile("ReplaceWithImage.docx", FileFormat.Docx);