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

Free Support Forum - aspose.com

Document having Text and Image interleaved - Image Floating

I am trying to create a document with Text and Images interleaved and I was able to do it. 

But the Image is floating over text as if its in a different layer.
So the text paragraphs that are added after the Image do NOT start at the end of the image but start at the end of the paragraph before the image.

public void CreateDocumentWithTextAndImage() throws Exception
{
	Run run = null;
	Paragraph para = null;
	Document doc = new Document();
	

	Section newSec = new Section(doc);
	doc.appendChild(newSec);
	
	Body newBody = new Body(doc);		
	newSec.appendChild(newBody);
	
	// First Paragraph		
	para = new Paragraph(doc);
	for ( int i = 0; i < 10; i++)
	{
		run = new Run(doc, "This is the text before the image ");		
		para.getRuns().add(run);
		
	}
	newBody.appendChild(para);
	
	
	// Second Paragraph is just am image
	para = new Paragraph(doc);
	Shape shape = new Shape(doc, ShapeType.IMAGE);
	shape.getImageData().setImage("C:\\temp\\OMD1.jpg");
	para.getRuns().add(shape);
	//para.appendChild(shape);
	newBody.appendChild(para);
	
	
	// Third Paragraph 
	para = new Paragraph(doc);
	for ( int i = 0; i < 10; i++)
	{
		run = new Run(doc, "This is the text after the image ");		
		para.getRuns().add(run);
			
	}
	newBody.appendChild(para);
	
	doc.save("C:\\temp\\temp.docx");
}

What am I missing here?

@KishoreVanapalli,

You need to make Shape Inline to fix this issue. Please try running the following code:

...
...
// Second Paragraph is just am image
para = new Paragraph(doc);
Shape shape = new Shape(doc, ShapeType.IMAGE);
shape.setWrapType(WrapType.INLINE);
shape.getImageData().setImage("D:\\temp\\aspose.words.png");
para.getRuns().add(shape);
//para.appendChild(shape);
newBody.appendChild(para);

// Third Paragraph
...
...

Hope, this helps.