Free Support Forum - aspose.com

Issue Related to inserting image into document

Hi Alexey,

Thank you for your service & help.

I am facing one problem while inserting image into document.

I am using Aspose.words for .net version 7.0.0.0

The sample report & image used in this report is also attached with this thread.

Please go through the attached sample document.

The requirement is that i want to move the image to left,right,top,bottom according to the pt values given by user. for e.g ( if i want a gap between 1 st table & image then i said top=20 )

I am using

DocumentBuilder.insertImage() API to insert image into document. where i cannot be able to specify the image position in terms of point values.

I don't want to create a floating text boxes inside which we can insert image & then move these boxes to different location.

The sample code is as follows.

private void button25_Click_1(object sender, EventArgs e)

{

string path = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);

//Initialize Aspose license.

Aspose.Words.License lic = new Aspose.Words.License();

lic.SetLicense(path + @"\Aspose.Total.lic");

Aspose.Pdf.License lic1 = new Aspose.Pdf.License();

lic1.SetLicense(path + @"\Aspose.Total.lic");

Document doc = new Document();

DocumentBuilder documentBuilder = new DocumentBuilder(doc);

//set the page set-up

PageSetup pageSetup = documentBuilder.CurrentSection.PageSetup;

documentBuilder.StartTable();

documentBuilder.CellFormat.Width = 100;

documentBuilder.CellFormat.Borders.LineStyle = LineStyle.Single;

documentBuilder.InsertCell();

documentBuilder.Write("Test text1");

documentBuilder.InsertCell();

documentBuilder.Writeln("Test text2");

documentBuilder.EndRow();

documentBuilder.EndTable();

documentBuilder.ParagraphFormat.ClearFormatting();

documentBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Center;

documentBuilder.InsertImage("MappleLeaf.GIF");

documentBuilder.ParagraphFormat.ClearFormatting();

documentBuilder.StartTable();

documentBuilder.CellFormat.Width = 100;

documentBuilder.CellFormat.Borders.LineStyle = LineStyle.Single;

documentBuilder.InsertCell();

documentBuilder.Write("Test text3");

documentBuilder.InsertCell();

documentBuilder.Writeln("Test text4");

documentBuilder.EndRow();

documentBuilder.EndTable();

doc.Save("sample.doc");

StartWord("sample.doc");

}

Is there any possible way to achieve this functionality in current scenario.

Please suggest any altrenative or workaround for this.

Waiting for your reply...!!!!!!!

Thanks & regards

Dwarika

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

Thanks for your request. Please try using the following code:

documentBuilder.ParagraphFormat.ClearFormatting();

// Set specing after the paragraph

documentBuilder.ParagraphFormat.SpaceAfter = 20;

// Set specing before the paragraph

documentBuilder.ParagraphFormat.SpaceBefore = 20;

documentBuilder.InsertImage("MappleLeaf.GIF");

documentBuilder.StartTable();

Hope this helps.

Best regards,

Hi AndreyN,

Thnaks for your suggeston & quick reply.

With reference to your above suggesetd way.

Is there anyway to move the image to left & right side?

Thanks & Regards,

Dwarika

Hi Dwarika,

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

Thanks for your inquiry. Of course you can. You can use ParagraphFormat.LeftIndent, ParagraphFormat.RightIndent and ParagraphFormat.Alignment to achieve this.

Hope this helps.

Best regards.