Unipdf pdf 创建 - 内容跨越多个页面的表格行存在显示问题

我正在使用 Unidoc 的 unipdf 库生成一个包含多个表的 pdf。
当表格单元格中的内容很大并且需要跨越多个页面时,生成的pdf会将行中的单元格打乱,每个单元格都会转到一个新页面,并且具有大量数据的单元格中不会显示任何数据.
在同样的情况下,有时我会看到这个进程挂起并且开始消耗大量内存。
以下是相同的屏幕截图:
Page1/cell1 - 单元格跨越整个页面,但只有一行

Page2/cell2 - 有实际的大量数据,但没有显示数据

Page3/cell3 - 单元格跨越整个页面但只有一行

执行上述操作的代码片段:

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 是否支持处理跨多个页面的数据?还是有一些选项/标志来启用它?我在这里想念什么?


慕田峪7331174
浏览 218回答 2
2回答

吃鸡游戏

您可以使用的另一种方法是创建GO HTML 模板并渲染它。使用wkhtmltopdf将 html 转换为 pdf。我也遇到了类似的问题,我无法生成复杂的 pdf,而使用 wkhtmltopdf 我能够生成它。ps:您可以使用pdfg.AddPage添加新页面。

www说

最新发布的UniPDF v3.16.0(刚刚发布)增加了对换行的支持,并且可以通过表格上的 EnableRowWrap 启用:t.EnableRowWrap(true)我们已经验证它适用于您上面发布的示例。如果您在最新版本中继续看到大量使用资源,请与我们分享。我们最近做了一些相当大的性能增强,并将继续改进它。获得好的错误报告是朝着这个目标迈出的一大步。披露:我是 UniPDF 的原始开发者。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go