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

Resize photo to fit Textbox after Replace

I replace {PHOTO} in a document using this code:

Dim paragraph As WParagraph = New WParagraph(doc)
Dim pictureW As WPicture
Dim textBodyPart As TextBodyPart = New TextBodyPart(doc)

pictureW = CType(paragraph.AppendPicture(b, WPicture)
textBodyPart.BodyItems.Add(paragraph)

doc.Replace("{PHOTO}", textBodyPart, False, False)

The problem is need to solve is that when {PHOTO} is inside a Textbox, the photo needs to resize to fit the Textbox.

How can I do this?

1 Reply

MJ Mohanaselvam Jothi Syncfusion Team October 11, 2019 01:21 AM

Hi Hugo,

Thank you for contacting Syncfusion support.

We have prepared a sample application to resize the photo to fit within the textbox as per your requirement and it can be downloaded from the below link:
https://www.syncfusion.com/downloads/support/forum/148227/ze/Sample702604310

Note: Please find the template Word document in “Data” folder of above sample application.

In the above sample, we have done the following things:
  1. Loads the template Word document.
  2. Appends picture to the new textbody part.
  3. Finds the text where to place an image in Word document.
  4. Resizes the width and height of the picture based on size of textbox.
  5. Replaces a place holder text with the text body part (picture).
  6. Saves the Word document.

Please let us know if you have any other questions.

Regards,
Mohanaselvam J
 


Loader.
Live Chat Icon For mobile
Up arrow icon