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

Free Support Forum - aspose.com

Fill textbox shape word document with a pictue file

Hi
I want to insert a textbox shape in my word document in a specified section. In my code everything is ok, only I cannot fill textbox with my specified picture file. Please give me a sample VB code to do that.
Thanks,

Dariush

My Code:

Public Function DocSignInsert(doc As Aspose.Words.Document, _SectionIndex As String)
Dim buld As DocumentBuilder = New DocumentBuilder(doc)
Dim img As Image = Image.FromFile("e:\s1.jpg")
Dim width As Double = ConvertUtil.PixelToPoint(img.Width, img.HorizontalResolution)
Dim height As Double = ConvertUtil.PixelToPoint(img.Height, img.VerticalResolution)
Dim builder As DocumentBuilder = New DocumentBuilder(doc)
Dim textbox As Shape = New Shape(doc, ShapeType.TextBox)
textbox.TextBox.FitShapeToText = True
textbox.Width = (width + (textbox.TextBox.InternalMarginLeft + textbox.TextBox.InternalMarginRight))
textbox.Height = (height + (textbox.TextBox.InternalMarginTop + textbox.TextBox.InternalMarginBottom))
textbox.WrapType = WrapType.Inline
textbox.Stroked = False

Dim converter As New ImageConverter
textbox.ImageData.SetImage(converter.ConvertTo(img, GetType(Byte()))) '.ImageBytes = converter.ConvertTo( "e:\s1.jpg", GetType(Byte())
buld.MoveToSection(_SectionIndex - 1)

textbox.AppendChild(New Paragraph(doc))
builder.InsertNode(textbox)
doc.Sections(_SectionIndex - 1).Body.FirstParagraph.AppendChild(textbox)
builder.MoveTo(textbox.FirstParagraph)
builder.InsertParagraph()
builder.Write("Dariush Ajami ")
Return Nothing

End Function

Hi Dariush,

Thanks for your inquiry. Please use one of following code example to achieve your requirements. Hope this helps you.

If you still face problem, please manually create your expected Word document using Microsoft Word and attach it here for our reference. We will investigate as to how you want your final Word output be generated like. We will then provide you more information on this along with code.

Dim doc As New Document()
Dim buld As DocumentBuilder = New DocumentBuilder(doc)
Dim img As Image = Image.FromFile("image.jpg")
Dim width As Double = ConvertUtil.PixelToPoint(img.Width, img.HorizontalResolution)
Dim height As Double = ConvertUtil.PixelToPoint(img.Height, img.VerticalResolution)
Dim builder As DocumentBuilder = New DocumentBuilder(doc)
Dim textbox As Shape = New Shape(doc, ShapeType.TextBox)
textbox.TextBox.FitShapeToText = True
textbox.Width = (width + (textbox.TextBox.InternalMarginLeft + textbox.TextBox.InternalMarginRight))
textbox.Height = (height + (textbox.TextBox.InternalMarginTop + textbox.TextBox.InternalMarginBottom))
textbox.WrapType = WrapType.Inline
textbox.Stroked = False
textbox.AppendChild(New Paragraph(doc))
builder.InsertNode(textbox)
builder.MoveTo(textbox.FirstParagraph)
builder.InsertImage("image.jpg")
' Save output.
doc.Save("Out.docx")
Dim doc As New Document()
Dim buld As DocumentBuilder = New DocumentBuilder(doc)
Dim img As Image = Image.FromFile("image.jpg")
Dim width As Double = ConvertUtil.PixelToPoint(img.Width, img.HorizontalResolution)
Dim height As Double = ConvertUtil.PixelToPoint(img.Height, img.VerticalResolution)
Dim builder As DocumentBuilder = New DocumentBuilder(doc)
Dim textbox As Shape = New Shape(doc, ShapeType.Image)
textbox.TextBox.FitShapeToText = True
textbox.Width = (width + (textbox.TextBox.InternalMarginLeft + textbox.TextBox.InternalMarginRight))
textbox.Height = (height + (textbox.TextBox.InternalMarginTop + textbox.TextBox.InternalMarginBottom))
textbox.WrapType = WrapType.Inline
textbox.Stroked = False
textbox.ImageData.SetImage("image.jpg")
builder.InsertNode(textbox)
' Save output.
doc.Save("Out.docx")

Hi Tahir,
Thanks for code but I can use of them because ,In first Code I don’t have my pics behind the Text in textbox, And it is important for me to have this.
In second Code I can’t have text in my TextBox because it is “ShapeType.image”.

I thing " textbox.Fill.ImageBytes " when textbox is ShapeType.TextBox , can help me but I don’t know how can I put my file as Image byest.
I check manually this in word (Filling TextBox by image File ) and is exactly whats I need.
Please let me know how can I textbox (ShapeType.TextBox) with a image file.
Thanks for your replay.

Dear Hahir, Plase check sampleOutput codument attache with this post.

Hi Dariush,

Thanks for sharing the detail. Unfortunately, Aspose.Words does not support the requested feature at the moment. However, we have logged this feature request as WORDSNET-12792 in our issue tracking system. You will be notified via this forum thread once this feature is available.

We apologize for your inconvenience.

Hi dear Tahir, Thanks for reply,
As you know textbox.Fill.ImageBytes is an aspose functionality. can you tell my how can i fill .imageBytes with a jpg file?

Hi Dariush,

Thanks for sharing the detail. The Fill.ImageBytes is read only property. We logged a feature request as WORDSNET-12792 to set Fill.ImageBytes value. You will be notified via this forum thread once this feature is available.

Please let us know if you have any more queries.

Hi Tahir ,
Can give an estimate time for adding this feature to aspose.word ?
Best regards
Dariush Ajami

Hi Dariush,

Thanks for your inquiry. It is to inform you that issues/feature are addressed and resolved based on first come first serve basis. Hopefully, this feature will be available in first quarter of 2016. Please note that this estimate is not final at the moment. We will be sure to inform you via this forum thread as soon as this feature is available.

Thank you for your patience and understanding.

The issues you have found earlier (filed as WORDSNET-12792) have been fixed in this Aspose.Words for .NET 22.1 update also available on NuGet.