We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Replace image to text

Hi !

I want to replace into a document an image with text.
I use Aspose.word version 3.5.3.0

My code :

Document doc = new Document(“file.doc”);
NodeCollection shapes = null;

shapes = doc.GetChildNodes(NodeType.Shape, true);
foreach (Shape shape in shapes)
{
if (shape.ImageFormat != null)
{
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveTo(shape);
// Replace image to text here
}
}

shapes = doc.GetChildNodes(NodeType.InlineShape, true);
foreach (InlineShape shape in shapes)
{
if (shape.ImageFormat != null)
{
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveTo(shape);
// Replace image to text here
}
}
doc.Save(“file.doc”);

Thanxs

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. You can try using the following code:

//Open Document and Create DocumentBuilder

Document doc = new Document(@"Test124\in.doc");

DocumentBuilder builder = new DocumentBuilder(doc);

//Get collection of Shapes

NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);

//Loop though all shapes

foreach (Shape shape in shapes)

{

if (shape.ShapeType == ShapeType.Image)

{

//move documentbuilder cursor to the shape

builder.MoveTo(shape);

//insert some text

builder.Write("[image]");

}

}

//Remove all shapes

shapes.Clear();

//Save output document

doc.Save(@"Test124\out.doc");

I use the latest version for testing.

Best regards.