我正在使用 Unidoc 的 unipdf 库生成一个包含多个表的 pdf。
当表格单元格中的内容很大并且需要跨越多个页面时,生成的pdf会将行中的单元格打乱,每个单元格都会转到一个新页面,并且具有大量数据的单元格中不会显示任何数据.
在同样的情况下,有时我会看到这个进程挂起并且开始消耗大量内存。
以下是相同的屏幕截图:
Page1/cell1 - 单元格跨越整个页面,但只有一行
Page2/cell2 - 有实际的大量数据,但没有显示数据
执行上述操作的代码片段:
func AddTableCell(c *ctx.Context, t *creator.Table, parag *creator.Paragraph, colSpan int, width float64, sides ...creator.CellBorderSide) {
cell := t.MultiColCell(colSpan)
for _, s := range sides {
cell.SetBorder(s, creator.CellBorderStyleSingle, width)
}
cell.SetHorizontalAlignment(creator.CellHorizontalAlignmentLeft)
cell.SetVerticalAlignment(creator.CellVerticalAlignmentMiddle)
err := cell.SetContent(parag)
c.NoError(err, "error setting cell content: %v", err)
}
func NewParagraph(c *creator.Creator, text string, font *pdfmodel.PdfFont, fontSize, lineHeight float64) *creator.Paragraph {
parag := c.NewParagraph(text)
parag.SetFont(font)
parag.SetFontSize(fontSize)
parag.SetColor(reportTextColor)
parag.SetLineHeight(lineHeight)
parag.SetEnableWrap(true)
return parag
}
这是我的两个函数,它们可以帮助我绘制表格
这是我如何使用它们的:
for col := 0; col < len(rowVals); col++ {
if col == 0 {
AddTableCell(g.c, tb.Table, NewParagraph(g.Creator, rowVals[col], font, 10, 1.5),
colSpans[col], tb.cellBorderWidth, creator.CellBorderSideAll)
} else {
AddTableCell(g.c, tb.Table, NewParagraph(g.Creator, rowVals[col], font, 10, 1.5),
colSpans[col], tb.cellBorderWidth, creator.CellBorderSideTop, creator.CellBorderSideRight, creator.CellBorderSideBottom)
}
if g.c.HasErr() {
return
}
}
使用相同的逻辑,我可以为较小的数据生成 pdf,但是当数据很大时它会中断,如上面的屏幕截图所示。
嵌入表格时,unidoc 是否支持处理跨多个页面的数据?还是有一些选项/标志来启用它?我在这里想念什么?
吃鸡游戏
www说
相关分类