We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Insert Image at Specific X/Y Postion

How do we insert Image at specific point lets say x,y Location.

Best Regards,

6 Replies

SY Sethumanikkam Yogendran Syncfusion Team February 20, 2017 04:37 AM UTC

Hi Nilofer,

Thank you for contacting Syncfusion support.

You can insert Image at specific position (Absolute positioned images) in Word document by setting value of “HorizontalPosition” and “VerticalPosition” for the picture using Essential DocIO.

Please refer below code example from our UG link Working with Images.
 
//Creates a new Word document
WordDocument document = new WordDocument();
//Adds new section to the document
IWSection section = document.AddSection();
//Adds new paragraph to the section
IWParagraph paragraph = section.AddParagraph();
paragraph.AppendText("This paragraph has picture. ");
//Appends new picture to the paragraph
IWPicture picture = paragraph.AppendPicture(Image.FromFile("Image.png"));
//Sets text wrapping style – When the wrapping style is inline, the images are not absolutely positioned.
//It is added next to the textrange.
picture.TextWrappingStyle = TextWrappingStyle.Square;
//Sets horizontal and vertical origin
picture.HorizontalOrigin = HorizontalOrigin.Page;
picture.VerticalOrigin = VerticalOrigin.Paragraph;
//Sets width and height for the paragraph
picture.Width = 150;
picture.Height = 100;
//Sets horizontal and vertical position for the picture
picture.HorizontalPosition = 200;
picture.VerticalPosition = 150;
picture.Name = "PictureName";
//Sets horizontal and vertical alignments
picture.HorizontalAlignment = ShapeHorizontalAlignment.Center;
picture.VerticalAlignment = ShapeVerticalAlignment.Bottom;
//Saves the Word document
document.Save("Sample.docx", FormatType.Docx);
//Closes the document
document.Close();
 

Please let us know if you have any other questions.

Regards,
Sethumanikkam.Y



NI Nilofer February 20, 2017 05:22 AM UTC

Thanks Sethumanikkam, I will check this 

Also how do we draw a line at specific x,y and later delete this line?

Best Regards,


NI Nilofer replied to Sethumanikkam Yogendran February 20, 2017 09:06 AM UTC

Hi Nilofer,

Thank you for contacting Syncfusion support.

You can insert Image at specific position (Absolute positioned images) in Word document by setting value of “HorizontalPosition” and “VerticalPosition” for the picture using Essential DocIO.

Please refer below code example from our UG link Working with Images.
 
//Creates a new Word document
WordDocument document = new WordDocument();
//Adds new section to the document
IWSection section = document.AddSection();
//Adds new paragraph to the section
IWParagraph paragraph = section.AddParagraph();
paragraph.AppendText("This paragraph has picture. ");
//Appends new picture to the paragraph
IWPicture picture = paragraph.AppendPicture(Image.FromFile("Image.png"));
//Sets text wrapping style – When the wrapping style is inline, the images are not absolutely positioned.
//It is added next to the textrange.
picture.TextWrappingStyle = TextWrappingStyle.Square;
//Sets horizontal and vertical origin
picture.HorizontalOrigin = HorizontalOrigin.Page;
picture.VerticalOrigin = VerticalOrigin.Paragraph;
//Sets width and height for the paragraph
picture.Width = 150;
picture.Height = 100;
//Sets horizontal and vertical position for the picture
picture.HorizontalPosition = 200;
picture.VerticalPosition = 150;
picture.Name = "PictureName";
//Sets horizontal and vertical alignments
picture.HorizontalAlignment = ShapeHorizontalAlignment.Center;
picture.VerticalAlignment = ShapeVerticalAlignment.Bottom;
//Saves the Word document
document.Save("Sample.docx", FormatType.Docx);
//Closes the document
document.Close();
 

Please let us know if you have any other questions.

Regards,
Sethumanikkam.Y


Hi, this is for a new document I guess I need to open a old document and put this image at x,y position.
In your case we need to create paragraphs and all which won't work in existing document,


SY Sethumanikkam Yogendran Syncfusion Team February 21, 2017 06:12 AM UTC

Hi Nilofer,

Thank you for your update.

We have prepared a sample to meet your requirement and in this sample, we have done the following things.

1. Loaded existing Word document using Essential DocIO.
2. Added image in specific (x, y) location.
3. Added line (shape) and delete it (if necessary) using helper method.
4. Saved modified Word document

Please find the sample from below link, and let us know if this helps you.
Sample link

Please let us know if you have any other questions.

Regards,
Sethumanikkam.Y



NI Nilofer February 21, 2017 07:56 AM UTC

Thanks Sethumanikkam, Appreciate your support.

Best Regards,


SY Sethumanikkam Yogendran Syncfusion Team February 22, 2017 04:26 AM UTC

Hi Nilofer,

Thank you for your update.

We are happy to hear that the provided solution resolved your requirement. Please let us know if you need any further assistance on this. We will be happy to assist you as always.

Please let us know if you have any other questions.

Regards,
Sethumanikkam.Y


Loader.
Live Chat Icon For mobile
Up arrow icon