i have a little problem with a special situation on a word document. The process of extracting images from a document is working fine so far. we just save the binary data of the doc without the images and replace the shapes with a bookmark to merge the document together later on in the process.
now my problem is a document where images are grouped together. trying to insert the bookmark or a field failed with:
Cannot insert a node of this type at this location.
Thanks for your query. Please see the following code snippet. In your case, you need to move the cursor’s position to parent node of GroupShape which is Paragraph node. Hope this helps you. Please let us know if you have any more queries.
Document doc = new Document(MyDir + "in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
// Get collection of group shapes
NodeCollection shapes = doc.GetChildNodes(NodeType.GroupShape, true);
// Loop through all group shapes
foreach (GroupShape shape in shapes)
{
builder.MoveTo(shape);
builder.MoveTo(builder.CurrentNode.ParentNode);
builder.StartBookmark("MyBookmark");
builder.Writeln("Text inside a bookmark.");
builder.EndBookmark("MyBookmark");
}
doc.Save(MyDir + "AsposeOut.Docx");
many thanks for the reply. your suggestion works pretty fine for me.
but now i run into another problem here.
normally we save the width and height from the shape to set the values for the image tag if we convert to html. it seems that the shape now if it is placed inside a group does not have valid width and height values anymore.
do you have any suggestions how i can solve this?
i already tried the ImageData.ImageSize but in here i only get the real size of the image and not the needed information in what size the image is shown in the document.
Thanks for your query. You can get the size of images in group shape as shown below. Hope this helps you. Please let us know if you have any more queries.
Document doc = new Document(MyDir + "in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
// Get collection of group shapes
NodeCollection shapes = doc.GetChildNodes(NodeType.GroupShape, true);
// Loop through all group shapes
foreach (GroupShape shape in shapes)
{
NodeCollection shape2 = shape.GetChildNodes(NodeType.Shape, true);
foreach (Shape image in shape2)
{
if (image.ImageData.HasImage)
{
SizeF size = image.GetShapeRenderer().SizeInPoints;
float height = size.Height;
float widht = size.Width;
}
}
}