dongliyan9190 2018-06-29 13:53
浏览 132

使用gofpdf编写Golang流或刷新大文件的内存

I have a pdf wrapper for gofpdf which is writing tables, the code to write rows looks like this, the headers of the table is another story...

func WriteTableRows(pdf *gofpdf.Fpdf, fontSize float64, columnSize []float64, rows [][]string) *gofpdf.Fpdf {
    pdf.SetFont("Times", "", fontSize)
    _, pageh := pdf.GetPageSize()
    marginCell := 2.
    _, _, _, mbottom := pdf.GetMargins()
    _, lineHt := pdf.GetFontSize()
    for _, row := range rows {
        curx, y := pdf.GetXY()

        x := curx
        height := splitLines(row, pdf, columnSize, lineHt, marginCell)
        y = AddAnotherPage(pdf, height, pageh, mbottom, y)

        for i, txt := range row {
            width := columnSize[i]
            pdf.Rect(x, y, width, height, "")
            pdf.MultiCell(width, lineHt+marginCell, txt, "", "", false)
            x += width
            pdf.SetXY(x, y)
        }
        pdf.SetXY(curx, y+height)
    }
    return pdf
}

This source code prepares a bunch of rows to be written in the pdf file, But the thing is that all information remains in memory and I have very big tables to write, how can I write what is already processed and free the memory without close the file, because after a bunch of rows prepared, I need to read another set and 'prepare' it again, or maybe even closing the file but open again to append the next set of rows.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 #MATLAB仿真#车辆换道路径规划
    • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
    • ¥15 数据可视化Python
    • ¥15 要给毕业设计添加扫码登录的功能!!有偿
    • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
    • ¥15 微信公众号自制会员卡没有收款渠道啊
    • ¥15 stable diffusion
    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条