使用gofpdf写入Golang流或刷新大文件的内存
我有一个用于gofpdf的pdf包装器,它正在编写表,用于编写行的代码如下所示,表的标题是另一个故事使用gofpdf写入Golang流或刷新大文件的内存,pdf,go,memory,Pdf,Go,Memory,我有一个用于gofpdf的pdf包装器,它正在编写表,用于编写行的代码如下所示,表的标题是另一个故事 func WriteTableRows(pdf *gofpdf.Fpdf, fontSize float64, columnSize []float64, rows [][]string) *gofpdf.Fpdf { pdf.SetFont("Times", "", fontSize) _, pageh := pdf.GetPageSize() marginCell :
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
}
这段源代码准备了一堆要写入pdf文件的行,
但问题是,所有信息都保留在内存中,我有非常大的表要写,我如何写已经处理过的内容并释放内存而不关闭文件,因为在准备了一堆行之后,我需要读取另一组并再次“准备”它,或者甚至关闭文件,但再次打开以附加下一组行