Free Support Forum - aspose.com

Insert mages into Aspose.words document not working

Hi!
I’m trying to insert an image into a blank (.doc) document and I’m not succeeding in this. I’ve read a couple of topics about this in the forum but none of the solutions worked for me.
It seems there is a problem with .doc and images being inserted dynamically, but might be a workaround to do this.
So far I’ve tried with shape.WrapType being “None”, “Tight” or “Square”. Any help would be appreciate it.
Here there is the snippet of my code:

Document mDocument = new Document();
DocumentBuilder mDocumentBuilder = new DocumentBuilder( mDocument );

Aspose.Words.Drawing.Shape shape = mDocumentBuilder.InsertImage( @“Signatures\mySignature.bmp” );
shape.WrapType = Aspose.Words.Drawing.WrapType.None;
shape.BehindText = true;
shape.RelativeHorizontalPosition = Aspose.Words.Drawing.RelativeHorizontalPosition.Page;
shape.HorizontalAlignment = Aspose.Words.Drawing.HorizontalAlignment.Center;
shape.RelativeVerticalPosition = Aspose.Words.Drawing.RelativeVerticalPosition.Page;
shape.VerticalAlignment = Aspose.Words.Drawing.VerticalAlignment.Center;

SaveFormat mAsposeSaveFormat = SaveFormat.Doc;
string sFilePath = “myDirectory\myFile.doc”;
mDocument.Save( sFilePath, mAsposeSaveFormat);

Thanks!

@Aida,

The code you shared inserts an image right at the middle of Page. Are you seeing any exceptions on your end? Please ZIP and upload your sample image file here for testing. We will then investigate the issue further on our end and provide you more information.

I’m not seeing any exceptions on my end and that’s what I don’t understand, everything seems to be alright, but it’s not.
Here you are the image I’m trying to insert:
jelsig.zip (2.9 KB)

@Aida,

Please check this output (18.10.zip (4.8 KB)) produced by using the following code with latest version of Aspose.Words for .NET i.e. 18.10.

Document mDocument = new Document();
DocumentBuilder mDocumentBuilder = new DocumentBuilder(mDocument);

Aspose.Words.Drawing.Shape shape = mDocumentBuilder.InsertImage("D:\\temp\\jelsig\\jelsig.bmp");
shape.WrapType = Aspose.Words.Drawing.WrapType.None;
shape.BehindText = true;
shape.RelativeHorizontalPosition = Aspose.Words.Drawing.RelativeHorizontalPosition.Page;
shape.HorizontalAlignment = Aspose.Words.Drawing.HorizontalAlignment.Center;
shape.RelativeVerticalPosition = Aspose.Words.Drawing.RelativeVerticalPosition.Page;
shape.VerticalAlignment = Aspose.Words.Drawing.VerticalAlignment.Center;

mDocument.Save("D:\\temp\\jelsig\\18.10.doc");

i’ve solved my issue. It didn’t have anything to do with your side, the error was on us. Since you told me the code worked for you I started trying other things until I found it. Your help put me in the right direction. Thanks!

@Aida,

It is great that you were able to resolve this issue on your end. Please let us know anytime you have any further queries.