有谁知道为什么我的桌子互相叠加?
Dim datatable As PdfPTable = New PdfPTable(4)
Dim page As Rectangle = document.PageSize
datatable.TotalWidth = page.Width - document.LeftMargin - document.RightMargin
datatable.DefaultCell.Border = 0
Dim datatable1 As PdfPTable = New PdfPTable(4)
datatable1.TotalWidth = page.Width - document.LeftMargin - document.RightMargin
datatable1.DefaultCell.Border = 0
Dim datatable2 As PdfPTable = New PdfPTable(4)
datatable2.TotalWidth = page.Width - document.LeftMargin - document.RightMargin
datatable2.DefaultCell.Border = 0
Dim last_pos As Integer = 580
Const xpos As Integer = 70
For i = 0 To extreme_foods.Count - 1
datatable.AddCell(extreme_foods(i))
Next
datatable.WriteSelectedRows(0, -1, xpos, last_pos, writer.DirectContent)
For i = 0 To moderate_foods.Count - 1
datatable1.AddCell(moderate_foods(i))
Next
last_pos = last_pos - datatable1.TotalHeight
datatable1.WriteSelectedRows(0, -1, xpos, last_pos, writer.DirectContent)
For i = 0 To light_foods.Count - 1
datatable2.AddCell(light_foods(i))
Next
last_pos = last_pos - datatable2.TotalHeight
datatable2.WriteSelectedRows(0, -1, xpos, last_pos, writer.DirectContent)
'document.Add(datatable)
Catch de As DocumentException
Console.Error.WriteLine(de.Message)
MessageBox.Show(de.Message)
Catch ioe As IOException
Console.Error.WriteLine(ioe.Message)
MessageBox.Show(ioe.Message)
Catch e As Exception
Console.Error.WriteLine(e.Message)
MessageBox.Show(e.Message)
End Try
document.Close()
即使我按照上一张桌子的高度递减last_pos
,他们仍然会以这样一种奇怪的方式翻身:
答案 0 :(得分:2)
你的减法只是一个微不足道的。你用当前表而不是前一个表减去last_pos
。你应该这样做:
Dim last_pos As Integer = 580
Const xpos As Integer = 70
For i = 0 To extreme_foods.Count - 1
datatable.AddCell(extreme_foods(i))
Next
datatable.WriteSelectedRows(0, -1, xpos, last_pos, writer.DirectContent)
For i = 0 To moderate_foods.Count - 1
datatable1.AddCell(moderate_foods(i))
Next
last_pos = last_pos - datatable.TotalHeight '<--- NOT datatable1'
datatable1.WriteSelectedRows(0, -1, xpos, last_pos, writer.DirectContent)