Yes Thanks, I think It’s good.
Now, I want to replace the first picture of the first page by a picture field.
My code :
Document doc = new Document(NameFile);
DocumentBuilder builder = new DocumentBuilder(doc);
NodeCollection shapes = null;
Shape shapeDelete = null;
InlineShape shapeInlineDelete = null;
// Search images in Shape
shapes = doc.GetChildNodes(NodeType.Shape, true);
foreach (Shape shape in shapes)
{
// If it’s an image and into the body
if (shape.ImageFormat != null && shape.GetAncestor(typeof(Body)) != null)
{
builder.MoveTo(shape);
builder.InsertField("INCLUDEPICTURE "" + LienImage + "" \d \* MERGEFORMAT", string.Empty);
shapeDelete = shape;
break;
}
}
// If shapeDelete is null, we continue to search with InlineShape
if (shapeDelete == null)
{
shapes = doc.GetChildNodes(NodeType.InlineShape, true);
foreach (InlineShape shape in shapes)
{
if (shape.ImageFormat != null && shape.GetAncestor(typeof(Body)) != null)
{
builder.MoveTo(shape);
builder.InsertField("INCLUDEPICTURE "" + LienImage + "" \d \* MERGEFORMAT", string.Empty);
shapeInlineDelete = shape;
break;
}
}
}
// Delete picture
if (shapeDelete != null) shapeDelete.Remove();
if (shapeInlineDelete != null) shapeInlineDelete.Remove();
doc.Save(NameFile);
But if the true first picture is in InlineShape, and that we take the first picture with Shape, I haven’t got good picture to replace…
Can I do this to have picture in the good order :
shapes = doc.GetChildNodes(NodeType.Shape | NodeType.InlineShape, true);
or maybe
shapes = doc.GetChildNodes(NodeType.Shape & NodeType.InlineShape, true);
Thanks, and I hope that you understand my english language
Edit : In fact, It’s good because there is only one picture into my document … Thxs !!!