'''' This code is part of Document Solutions for Word demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.IOImportsSystem.DrawingImportsSystem.Collections.GenericImportsSystem.LinqImportsGrapeCity.Documents.Word '' This sample demonstrates how to add linked text frames to a DOCX,'' with text spanning the frames.PublicClassTextFramesPublicFunctionCreateDocx() AsGcWordDocumentDim doc = NewGcWordDocument() doc.Load(Path.Combine("Resources", "WordDocs", "SampleParagraphs.docx")) '' Locate the paragraphs for inserting text frames:Constp1start = "This is the first paragraph of the original document"Constp2start = "This is the second paragraph of the original document"Constp3start = "This is the third paragraph of the original document"Constp4start = "This is the fourth paragraph of the original document" '' Find individual paragraphs inside the document:Dim p1 = Nothing, p2 = Nothing, p3 = Nothing, p4 = NothingForEach p In doc.Body.ParagraphsDim t = p.GetRange().TextIf (t.StartsWith(p1start)) Then p1 = pElseIf (t.StartsWith(p2start)) Then p2 = pElseIf (t.StartsWith(p3start)) Then p3 = pElseIf (t.StartsWith(p4start)) Then p4 = pEndIfNextIf p1 IsNothingOrElse p2 IsNothingOrElse p3 IsNothingOrElse p4 IsNothingThenThrowNew Exception("Unexpected: could not find paragraphs.")EndIf '' Add new style for text in frames:Dim style = doc.Styles.Add("FrameTextStyle", StyleType.Character) style.Font.Color.RGB = Color.DarkBlue style.Font.Bold = True '' Generate a long text that we will put into linked text frames:Dim ts = ""For i = 0To11 ts += $"Text frame content {i}. "Next '' NOTE: shapes (including text frames) can be added to text runs only'' (e.g. we cannot add a shape directly to a paragraph). '' Add a text run at the end of the first paragraph:Dim r1 = p1.GetRange().Runs.Add(" Text run added to paragraph 1. The first shape is inserted inline after this. ") '' Add a shape to the new text run:Dim s1 = r1.GetRange().Shapes.Add(96, 72) '' Add a text frame with the generated text to the new shape:Dim tf1 = s1.AddTextFrame(CType(ts, String)) tf1.Format.Margin.AllEdges = 4 ForEach r In tf1.GetRange().RunsIf r1 IsNot r Then r.Style = styleEndIfNext '' The text in the frame is rather long, and will not fit inside s1.'' Text frames can be linked so that a long text can span several frames.'' We add two linked frames, one to 2nd paragraph, and one to the first'' paragraph on the page:Dim r2 = p2.GetRange().Runs.Add(" Text run added to paragraph 2. The second shape is inserted inline after this. ")Dim shapes = r2.GetRange().Shapes Dim s2 = r2.GetRange().Shapes.Add(192, 72)Dim ltf2 = s2.AddLinkedTextFrame(tf1) '' Default wrap format type for new shapes is inline.'' Here we change the 3rd shape's wrap to square with absolute position'' relative to the very first paragraph in the document:Dim s3 = doc.Body.Paragraphs.First.GetRange().Runs.First.GetRange().Shapes.Add(144, 96)Dim ltf3 = s3.AddLinkedTextFrame(tf1) s3.WrapFormat.Type = WrapType.Square s3.Position.Vertical.Type = ShapePositionType.Points s3.Position.Vertical.Offset = 0 s3.Position.Horizontal.Type = ShapePositionType.Points s3.Position.Horizontal.Offset = doc.Body.Sections.First.PageSetup.ClientWidth - 144 Return docEndFunctionEndClass