' load long string from resource file
Dim text As String = Strings.ResourceNotFound
Using sr = New StreamReader(GetType(BasicTextPage).GetTypeInfo().
Assembly.GetManifestResourceStream("WordSamples.Resources.flow.txt"))
text = sr.ReadToEnd()
End Using
text = text.Replace(vbTab, " ")
' create word document
word.Info.Title = "Text Flow"
' table
Dim rows As Integer = 4
Dim cols As Integer = 2
Dim table As New RtfTable(rows, cols)
word.Add(table)
table.Rows(0).Cells(0).SetMerged(1, 2)
For row As Integer = 0 To rows - 1
If row = 0 Then
table.Rows(row).Height = 50
End If
For col As Integer = 0 To cols - 1
'RtfParagraph paragraph = new RtfParagraph();
'paragraph.Alignment = RtfHorizontalAlignment.Undefined;
'paragraph.Content.Add(new RtfString(string.Format("table cell {0}:{1}.", row, col)));
'table.Rows[row].Cells[col].Content.Add(paragraph);
table.Rows(row).Cells(col).Content.Add(New RtfString(String.Format("table cell {0}:{1}.", row, col)))
If row = 0 AndAlso col = 0 Then
table.Rows(row).Cells(col).Alignment = ContentAlignment.MiddleCenter
table.Rows(row).Cells(col).BackFilling = Colors.LightPink
Else
table.Rows(row).Cells(col).BackFilling = Colors.LightYellow
End If
table.Rows(row).Cells(col).BottomBorderWidth = 2
table.Rows(row).Cells(col).TopBorderWidth = 2
table.Rows(row).Cells(col).LeftBorderWidth = 2
table.Rows(row).Cells(col).RightBorderWidth = 2
Next
Next
Return
' add title
Dim titleFont As New Font("Tahoma", 24, RtfFontStyle.Bold)
Dim bodyFont As New Font("Tahoma", 9)
Dim rcPage As Rect = WordUtils.PageRectangle(word)
Dim rc As Rect = WordUtils.RenderParagraph(word, word.Info.Title, titleFont, rcPage, rcPage, False)
rc.Y += titleFont.Size + 6
rc.Height = rcPage.Height - rc.Y
' create two columns for the text
Dim rcLeft As Rect = rc
rcLeft.Width = rcPage.Width / 2 - 12
rcLeft.Height = 300
rcLeft.Y = (rcPage.Y + rcPage.Height - rcLeft.Height) / 2
Dim rcRight As Rect = rcLeft
rcRight.X = rcPage.Right - rcRight.Width
' start with left column
rc = rcLeft
' render string spanning columns and pages
While True
' render as much as will fit into the rectangle
rc = WordUtils.Inflate(rc, -3, -3)
'int nextChar = word.DrawString(text, bodyFont, Colors.Black, rc);
word.DrawString(text, bodyFont, Colors.Black, rc)
rc = WordUtils.Inflate(rc, +3, +3)
word.DrawRectangle(Colors.LightGray, rc)
' break when done
'if (nextChar >= text.Length)
If True Then
Exit While
End If
' get rid of the part that was rendered
'text = text.Substring(nextChar);
' switch to right-side rectangle
If rc.Left = rcLeft.Left Then
rc = rcRight
Else
' switch to left-side rectangle on the next page
word.PageBreak()
rc = rcLeft
End If
End While