jung-kurt / gofpdf

A PDF document generator with high level support for text, drawing and images
http://godoc.org/github.com/jung-kurt/gofpdf
MIT License
4.31k stars 777 forks source link

Blank document when I add a page #275

Closed mmcmm closed 5 years ago

mmcmm commented 5 years ago

When I use AddPage I just get a white/blank file, and can't seem to figure it why, I even tried with the basic examples. Also auto page break point doesn't work. If I use AddPage after I have written to the document I get some infinite loop as it crashes.

Thanks

jung-kurt commented 5 years ago

Can you include the smallest possible program that causes these problems?

Does the following program work for you?

package main

import (
  "fmt"
  "os"

  "github.com/jung-kurt/gofpdf/v2"
)

func main() {
  pdf := gofpdf.New("P", "mm", "A4", "")
  pdf.AddPage()
  pdf.SetFont("Arial", "B", 16)
  pdf.Cell(40, 10, "Hello, world")
  err := pdf.OutputFileAndClose("hello.pdf")
  if err != nil {
    fmt.Fprintln(os.Stderr, err)
  }
}
mmcmm commented 5 years ago

Thank you for the reply, turns out it was my issue, I was doing all the drawing in the header function and I guess when you call AddPage from the header function some kind of recursion forms.

jung-kurt commented 5 years ago

Thanks for the followup!