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

Free Support Forum - aspose.com

How do you center a TextBox in the output Html?

I have looked at a number of forum posts, and I have tried the following code.

ncShapes = documentWord.GetChildNodes(NodeType.Shape, True)
For Each shapeNode As Shape In ncShapes
shapeNode.HorizontalAlignment = HorizontalAlignment.Center
shapeNode.ParentParagraph.ParagraphFormat.Alignment = ParagraphAlignment.Center
Next

But the Html element that results for the TextBox is never centered. It always ends up with some other alignment specification that seems to depend on the Wrapping Style of the TextBox in the original Word document. In some cases it creates the element with a float: left; alignment, in other cases a position: absolute; zorder: 0; alignment, and so on, but never centered.

How do you center a TextBox in the output Html? We are using version 11.11.0.0 (v2.0.50727). Thanks.

Hi John,


Thanks for your inquiry. Could you please attach your input Word document and your target HTML document showing the desired behaviour here for testing? I will investigate the issue on my side and provide you more information.

Best regards,

Thank you for your response. Below is the code for the actual method we are using to perform the conversion. Attached are the Word document, the Aspose Html that results from the code below, and a possible Html we expected to get. You will notice that the element you create in the Aspose.html file has a style attribute with float:left specified, and its parent

element has a style attribute with text-align:justify specified. Since we changed those using your API in the code below, we instead expected to get something like a text-align:center (or something that would center the resulting image) specified for the style attributes in the and

elements.


Private Function ConvertWordDocumentToHtml(ByVal documentWord As Aspose.Words.Document) As String

Dim mStream As MemoryStream
Dim hsOptions As HtmlSaveOptions
Dim ncShapes As NodeCollection
Dim sReader As StreamReader

Try

mStream = New MemoryStream()

hsOptions = New HtmlSaveOptions()
With (hsOptions)
.ExportImagesAsBase64 = False
.ExportHeadersFootersMode = ExportHeadersFootersMode.None
.ImagesFolder = MapPath("~/Images/Uploaded/")
.SaveFormat = SaveFormat.Html
End With

ncShapes = documentWord.GetChildNodes(NodeType.Shape, True)
For Each shapeNode As Shape In ncShapes
shapeNode.HorizontalAlignment = HorizontalAlignment.Center
If (Not IsNothing(shapeNode.ParentParagraph))
shapeNode.ParentParagraph.ParagraphFormat.Alignment = ParagraphAlignment.Center
End If
Next

documentWord.Save(mStream, hsOptions)

mStream.Position = 0

sReader = New StreamReader(mStream)

Return sReader.ReadToEnd()

Catch ex As Exception

Return String.Empty

End Try

End Function

Hi John,


Thanks for your inquiry. Here is the sample code to achieve the desired image position in HTML:

Dim doc As New Document(“C:\Temp\Economia
& Politica 2012-08-09.doc”
)

Dim targetShape As Shape = TryCast(doc.GetChildNodes(NodeType.Shape, True)(3), Shape)

targetShape.ParentParagraph.ParagraphFormat.Alignment = ParagraphAlignment.Center

targetShape.WrapType = WrapType.Inline

doc.Save(“C:\Temp\out.html”)


I hope, this helps.

Best regards,

Adding the following line from your code above to our method is what makes it work.


targetShape.WrapType = WrapType.Inline

Now the TextBox is centered in the output Html. Thank you for your help.

Hi John,


Thanks for your feedback on this. Please let us know any time you have any further queries. We are always glad to help you.

Best regards,