當逐字建立 TextFragment 且長度超過儲存格寬度時,不會自動換行
PDF 版本: 24.8
下圖為問題所在,
左邊的儲存格使用同一個 TextSegment 會自動換行;
右邊的每個字使用一個 TextSegment 時,超過欄寬不會換行。
Pic.png (12.8 KB)
Dim Words As String = "甲乙丙丁戊己庚辛壬癸子丑寅卯辰巳午未申酉戌亥忠孝仁愛信義和平"
Dim pDoc As New Aspose.Pdf.Document()
Dim pPage As Aspose.Pdf.Page = pDoc.Pages.Add()
pPage.SetPageSize(Aspose.Pdf.PageSize.A4.Width, Aspose.Pdf.PageSize.A4.Height)
Dim pTable As New Aspose.Pdf.Table With {
.ColumnWidths = "60% 40%",
.RepeatingRowsCount = 2,
.DefaultCellBorder = New Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 1.0F)
}
pPage.Paragraphs.Add(pTable)
Dim pRows As Aspose.Pdf.Rows = pTable.Rows
Dim R1 As Aspose.Pdf.Row = pRows.Add()
Dim R1C1 As Aspose.Pdf.Cell = R1.Cells.Add("Word")
Dim R1C2 As Aspose.Pdf.Cell = R1.Cells.Add("Text")
Dim R2 As Aspose.Pdf.Row = pRows.Add()
R2.IsRowBroken = True
Dim R2C1 As Aspose.Pdf.Cell = R2.Cells.Add("甲乙丙丁戊己庚辛壬癸子丑寅卯辰巳午未申酉戌亥忠孝仁愛信義和平")
Dim R2C2 As Aspose.Pdf.Cell = R2.Cells.Add()
Dim R2C2_TF As New Aspose.Pdf.Text.TextFragment()
For i As Integer = 0 To Words.Length - 1
Dim TextSeg As New Aspose.Pdf.Text.TextSegment With {.Text = Mid(Words, i + 1, 1)}
TextSeg.TextState.FontSize = 8 + i
TextSeg.TextState.Font = Aspose.Pdf.Text.FontRepository.FindFont("PMingLiU")
R2C2_TF.Segments.Add(TextSeg)
Next
Dim R2C2Parag As New Aspose.Pdf.Paragraphs From {R2C2_TF}
R2C2.Paragraphs = R2C2Parag
pDoc.Save("X:\Coding\PDF_.pdf")