Hi,
Thank you for your feedback.
1. According to your first post ("there is one image inside textbox"), I learned that your word has a textbox object that contains an image, and you want to extract the whole object as a picture. Our Spire.Doc could achieve it. Sample code is shown in below code.
2. As for the overlapping objects you mentioned in last post, if it is a shape group, it can also be extracted as a picture. Please refer to the following code.
If this is not what you want, please provide further information to help us have a better understanding. Sharing your sample Word document will be greatly helpful, we promise to keep your document confidential and we will not use it for any other purpose. So you can remove sensitive information and then send it to our email (
support@e-iceblue.com).
- Code: Select all
static void Main(string[] args)
{
Document doc = new Document();
doc.LoadFromFile(input);
int shapeCount = 0;
foreach (Section section in doc.Sections)
{
foreach (Paragraph para in section.Paragraphs)
{
foreach (DocumentObject obj in para.ChildObjects)
{
if (obj.DocumentObjectType == DocumentObjectType.TextBox)
{
TextBox textbox = obj as TextBox;
string fileName = string.Format("Image-{0}.png", shapeCount);
Image image = ConverTextBoxToImage(textbox);
image.Save(fileName, ImageFormat.Png);
shapeCount++;
}
if (obj.DocumentObjectType == DocumentObjectType.ShapeGroup)
{
ShapeGroup shapeGroup = obj as ShapeGroup;
string fileName = string.Format("Image-{0}.png", shapeCount);
Image image = ConverShapeToImage(shapeGroup);
image.Save(fileName, ImageFormat.Png);
shapeCount++;
}
}
}
}
}
public static Image ConverTextBoxToImage(TextBox textBox)
{
Document document = new Document();
Section section = document.AddSection();
section.AddParagraph().ChildObjects.Add(textBox.Clone());
Image image = document.SaveToImages(0, ImageType.Bitmap);
document.Close();
return image;
}
public static Image ConverShapeToImage(ShapeGroup group)
{
Document document = new Document();
Section section = document.AddSection();
section.AddParagraph().ChildObjects.Add(group.Clone());
Image image = document.SaveToImages(0, ImageType.Bitmap);
document.Close();
return image;
}
Sincerely,
Annika
E-iceblue support team