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

我有一个用于写表的gofpdf的pdf包装器,用于写行的代码如下所示, 该表是另一个故事... </ p>

  func WriteTableRows(pdf * gofpdf.Fpdf,fontSize float64,columnSize [] float64,行[] [] string)* gofpdf.Fpdf  {
pdf.SetFont(“ Times”,“”,fontSize)
,pageh:= pdf.GetPageSize()
marginCell:= 2.
_,
,_,mbottom:= pdf.GetMargins( )
_,lineHt:= pdf.GetFontSize()
_,行:=范围行{
curx,y:= pdf.GetXY()

x:= curx
高度:= splitLines( 行,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 + =宽度
pdf.SetXY(x,y )
}
pdf.SetXY(curx,y + hei ght)
}
返回pdf
}
</ code> </ pre>

此源代码准备了许多要写入pdf文件的行,
但是 所有信息都保留在内存中,并且我有非常大的表要写入,如何写已处理的内容并释放内存而不关闭文件,因为在准备好一堆行之后,我需要读取另一组并“准备” 再次,甚至关闭文件,但再次打开以追加下一组行。 </ p>
</ div>

展开原文

原文

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.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐