Ms word textframe

Do you have a comperable object for ms word “textframe” in aspos words?

Hi
Thanks for your request. Maybe you can use TextBox. Please see the following code example:

// Create document
Document doc = new Document();
// Create new text Run
Run run = new Run(doc, "Some text");
Paragraph paragraph = new Paragraph(doc);
// Add text to paragraph
paragraph.AppendChild(run);
// Create New Shape as text box
Shape textBox = new Shape(doc, ShapeType.TextBox);
textBox.Width = 100;
textBox.Height = 100;
// Assign paragraph to shape
textBox.AppendChild(paragraph);
// Insert textbox into the document
doc.FirstSection.Body.FirstParagraph.AppendChild(textBox);
// Save output document
doc.Save("out.doc");

Hope this helps.
Best regards.

It seems you have the textframe object in aspose.slides. Is this broken off from msword funtionality?
If yes,.could i have both aspose,words and aspose. slides together working on a single document?

Hi
Thanks for your inquiry. Aspose.Slides can work only with PowerPoint documents, so you can process Word document using Aspose.Slides.
TextFrames are preserved during processing of the document using Aspose.Words. Could you tell me why and where you would like to use Frames. Actually, Frames are feature of old version of MS Word. Currently, TextBoxes are used instead of Frames.
Best regards.

I want to convert the following function to aspose.
the bookmarks are imbedded in a template doc file.

Private Function processLongTextField(ByRef startBookmark As String, ByRef continueBookmark As String, ByRef filename As String, ByRef LargeHeader As Boolean) As Boolean
' Returns true if continuation is used or false if text fits in first box
On Error GoTo errorHandler
Dim myShape As Microsoft.Office.Interop.Word.Shape
Dim myBookmark As Microsoft.Office.Interop.Word.Bookmark
Dim myTextFrame As Microsoft.Office.Interop.Word.TextFrame
Dim myTextBox As Microsoft.Office.Interop.Word.Shape
Dim myRange As Microsoft.Office.Interop.Word.Range
Dim boolContinuing As Boolean
Dim boxWidth As Single
Dim boxHeight As Single
Dim bPageBreak As Boolean
' jls 3/14/2007 ***********************************************************************************
Dim boxTop As Single
' jls 3/14/2007 ***********************************************************************************
boolContinuing = False
For Each myShape In Wrd.ActiveDocument.Shapes
If myShape.Anchor.Bookmarks.Exists(startBookmark) Then
myTextFrame = myShape.TextFrame
Exit For
End If
Next myShape
If myTextFrame Is Nothing Then Exit Function
myTextFrame.TextRange.Select()
Wrd.Selection.InsertFile(filename:=filename, Link:=False, ConfirmConversions:=False)
'Delete extra paragraph at end of text
Wrd.Selection.Collapse(Direction:=Microsoft.Office.Interop.Word.WdCollapseDirection.wdCollapseEnd)
Wrd.Selection.Delete(Unit:=Microsoft.Office.Interop.Word.WdUnits.wdCharacter, Count:=1)
'Change Space after last parargraph to zero - SPCR #564
With Wrd.Selection.ParagraphFormat
.SpaceAfter = 0
' .SpaceAfterAuto = False
End With
'DSL 6/5/2002
'Resize the Graphics in the Text Box before processPageBreakInTextBox
'select the graphics and resize here
ResizeGraphics(myTextFrame.TextRange.InlineShapes)
bPageBreak = processPageBreakInTextBox(myTextFrame)
Do While myTextFrame.Overflowing Or bPageBreak
If boolContinuing Then
' Add a new page and insert continution text box
myRange.Move(Unit:=Microsoft.Office.Interop.Word.WdUnits.wdParagraph, Count:=1)
myRange.InsertParagraphAfter()
myRange.Collapse()
myRange.InsertBreak(Type:=Microsoft.Office.Interop.Word.WdBreakType.wdPageBreak)
myRange.Collapse(Microsoft.Office.Interop.Word.WdCollapseDirection.wdCollapseEnd)
myRange.MoveEnd(Microsoft.Office.Interop.Word.WdUnits.wdCharacter, 1)
Else
' Insert continuation text box on page with continueBookmark
myRange = Wrd.ActiveDocument.Bookmarks.Item(continueBookmark).Range
myRange.Collapse()
boolContinuing = True
End If
boxWidth = Wrd.InchesToPoints(7.375)
If LargeHeader Then
boxHeight = Wrd.InchesToPoints(6.775)
Else
boxHeight = Wrd.InchesToPoints(7.375)
End If
' want to make box height dependeant on amount of space left on page
' the following code did not work as expected
' boxHeight = Wrd.InchesToPoints(10#) - myRange.Information(wdVerticalPositionRelativeToTextBoundary)
pause(1)
'myRange.Select

' jls 3/14/2007 ***********************************************************************************
'Set myTextBox = Wrd.ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 3.6, 4.4, boxWidth, boxHeight, myRange)
boxTop = Wrd.InchesToPoints(0.125)
myTextBox = Wrd.ActiveDocument.Shapes.AddTextbox(Office.MsoTextOrientation.msoTextOrientationHorizontal, 0, boxTop, boxWidth, boxHeight, myRange)
' jls 3/14/2007 ***********************************************************************************
myTextBox.Line.Visible = Office.MsoTriState.msoFalse
'myTextBox.WrapFormat.Type = wdWrapTopBottom
''myTextBox.WrapFormat.Side = wdWrapBoth
'myTextBox.WrapFormat.DistanceTop = Wrd.InchesToPoints(0)
'myTextBox.WrapFormat.DistanceBottom = Wrd.InchesToPoints(0)
''myTextBox.WrapFormat.DistanceLeft = Wrd.InchesToPoints(0.13)
''myTextBox.WrapFormat.DistanceRight = Wrd.InchesToPoints(0.13)
myTextBox.Left = Microsoft.Office.Interop.Word.WdShapePosition.wdShapeLeft
' jls 3/14/2007 ***********************************************************************************
'If LargeHeader Then
' myTextBox.Top = Wrd.InchesToPoints(2.73)
'Else
' myTextBox.Top = Wrd.InchesToPoints(2.13)
'End If
' jls 3/14/2007 ***********************************************************************************
myTextBox.RelativeVerticalPosition = Microsoft.Office.Interop.Word.WdRelativeVerticalPosition.wdRelativeVerticalPositionPage
If bPageBreak Then
' Paste text after page break into new text box
myTextBox.TextFrame.TextRange.Paste()
Else
' link to new text box so that overflow will go there
myTextFrame.Next = myTextBox.TextFrame
End If
myTextFrame = myTextBox.TextFrame
pause(1)
bPageBreak = processPageBreakInTextBox(myTextFrame)
Loop
processLongTextField = boolContinuing
Exit Function
errorHandler:
RaiseError("processLongTextField(" & startBookmark & ")")
End Function

Hi
Thanks for your request. There are also the following functions
ResizeGraphics
processPageBreakInTextBox
Please provide me code of these methods, so I will be able to fully understand what this code does. Also, please attach your documents for testing.
Best regards.

Private Sub ResizeGraphics(ByRef MyShapes As Microsoft.Office.Interop.Word.InlineShapes)
On Error GoTo errorHandler
For Each aGraphic In MyShapes
If aGraphic.Type = Microsoft.Office.Interop.Word.WdInlineShapeType.wdInlineShapeLinkedOLEObject Or aGraphic.Type = Microsoft.Office.Interop.Word.WdInlineShapeType.wdInlineShapeLinkedPicture Then
' resize the image if too large
' aGraphic.LockAspectRatio = msoTrue
' aGraphic.Reset
If aGraphic.Width > MaxGraphicWidth Then
'''' aGraphic.ScaleWidth = 504 / aGraphic.Width
aGraphic.Height = aGraphic.Height * MaxGraphicWidth / aGraphic.Width
aGraphic.Width = MaxGraphicWidth
End If
If aGraphic.Height > MaxGraphicHeight Then
aGraphic.Width = aGraphic.Width * MaxGraphicHeight / aGraphic.Height
aGraphic.Height = MaxGraphicHeight
End If
''Commented Out for PDF Print
'' aGraphic.LinkFormat.Update
'' aGraphic.LinkFormat.BreakLink
End If
Next aGraphic
Exit Sub
errorHandler:
RaiseError("ResizeGraphics")
End Sub
Private Function processPageBreakInTextBox(ByRef myTextFrame As Microsoft.Office.Interop.Word.TextFrame) As Boolean
' Process page breaks in textframe fields
On Error GoTo errorHandler
processPageBreakInTextBox = False
myTextFrame.TextRange.Select()
Wrd.Selection.Find.ClearFormatting()
With Wrd.Selection.Find
.Text = "[page break]"
.Forward = True
.Wrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue
.Execute()
If .Found = True Then
'UPGRADE_WARNING: Couldn't resolve default property of object Wrd.Selection.Information(wdVerticalPositionRelativeToPage). Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
If Wrd.Selection.Information(Microsoft.Office.Interop.Word.WdInformation.wdVerticalPositionRelativeToPage) <> -1 Then
Wrd.Selection.TypeParagraph()
processPageBreakInTextBox = True
Wrd.Selection.MoveEnd(Unit:=Microsoft.Office.Interop.Word.WdUnits.wdStory)
Wrd.Selection.Cut()
End If
'MVB PAGEBREAK ERRORS BECAUSE ONE LINE WAS COMMENTED OUT AND THE PAGEBREAK
'DELETE WAS NOT DONE HERE -7/11/03
Wrd.Selection.MoveEnd(Unit:=Microsoft.Office.Interop.Word.WdUnits.wdLine, Count:=1)
Wrd.Selection.Delete()
End If
End With
Exit Function
errorHandler:
RaiseError("processPageBreakInTextBox")
End Function
Private Sub processPageBreaks(ByRef myRange As Microsoft.Office.Interop.Word.Range)
On Error GoTo errorHandler
Do While True
myRange.Select()
With Wrd.Selection.Find
.ClearFormatting()
.Text = "[page break]"
.Forward = True
.Wrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue
.Execute()
If .Found = False Then
Exit Sub
End If
Wrd.Selection.Delete()
Wrd.Selection.InsertBreak(Type:=Microsoft.Office.Interop.Word.WdBreakType.wdPageBreak)
End With
Loop
Exit Sub
errorHandler:
RaiseError("processPageBreaks)")
End Sub

Hi
Thank you for additional information. As I can see this code inserts HTML into the textbox, and if content overflows the textbox it creates a linked textbox at the next page. Unfortunately, linked textboxes are not supported by Aspose.Words. This is known issue #6970 in our defect database.
However, I think in your case it would be enough just move DocumentBuilder cursor to the bookmark and insert HTML. See the following code:

'Open document and create DocumentBuilder
Dim doc As Document = New Document("C:\Temp\in.doc")
Dim builder As DocumentBuilder = New DocumentBuilder(doc)
'move DocumentBuilder cursor to the bookmark
builder.MoveToBookmark("myBookmark")
'Read HTML from file
Dim html As String = File.ReadAllText("C:\Temp\myHtmlFile.html")
'Insert HTML at bookamrk
builder.InsertHtml(html)
'Save document
doc.Save("C:\Temp\out.doc")

Hope this helps.
Best regards,

I’m not sure iIget your response. Our code creates a new page for overflowing text/images using the continuation bookmark in the calling sequence.
Also, executing the code from your example:

Builder.InsertHtml(html)

generates and error: “Argument ‘Number’ is not a valid value.”

Hi
Thank you for additional information. Unfortunately, there is no way to determine whether content overflows the page or not using Aspose.Words.
Regarding problem with HTML insertion, Could you please provide me HTML that causes the problem. I tried to insert HTML you have attached earlier, but no errors occurs on my side.
Best regards.