FPDF stream write with gofpdf or flush the memory for big files

435 views
Skip to first unread message

Grace Pahuasi

unread,
Jul 2, 2018, 10:54:28 PM7/2/18
to golang-nuts
hello alldown vote

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.



Maybe it is duplicated or something, I have the same question posted on stackoverflow:

https://stackoverflow.com/questions/51103364/golang-stream-write-with-gofpdf-or-flush-the-memory-for-big-files

Any help is appreciated, thanks,

Grace

Manlio Perillo

unread,
Jul 3, 2018, 8:44:57 AM7/3/18
to golang-nuts
Il giorno martedì 3 luglio 2018 04:54:28 UTC+2, Grace Pahuasi ha scritto:
hello alldown vote

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...

> [...]
 

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,


I don't know gopdf, but I can assume that it stores all the data in memory and only writes the data to the file when the document is finished.
As far as I know many PDF implementations do this, so there is probably nothing that can you do.

Note however that this is not a problem with the PDF file format, but with the implementations.
Some time ago I wrote a PDF implementation in Python that writes data to the file incrementally.
The only data stored in memory is the one required for the cross-reference table.


Manlio

Grace Pahuasi

unread,
Jul 3, 2018, 9:19:53 PM7/3/18
to manlio....@gmail.com, golan...@googlegroups.com
Thanks for your answer, write the data to the file incrementally is what I would like to do with FPDF ... 

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
--
Grace

nanmu42

unread,
Jul 4, 2018, 12:49:28 AM7/4/18
to golang-nuts
Maybe this would be a little help:

https://github.com/jung-kurt/gofpdf/issues/110

Grace Pahuasi

unread,
Jul 5, 2018, 12:47:22 AM7/5/18
to vis...@gmail.com, golan...@googlegroups.com
Thanks, 

El mié., 4 jul. 2018 a las 0:49, nanmu42 (<vis...@gmail.com>) escribió:
Maybe this would be a little help:

https://github.com/jung-kurt/gofpdf/issues/110

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
--
Grace
Reply all
Reply to author
Forward
0 new messages