1. 生成PDF

    1. import (
    2. "github.com/jung-kurt/gofpdf"
    3. )
    4. func main() {
    5. err := GeneratePdf("hello.pdf")
    6. if err != nil {
    7. panic(err)
    8. }
    9. // GeneratePdf generates our pdf by adding text and images to the page
    10. // then saving it to a file (name specified in params).
    11. func GeneratePdf(filename string) error {
    12. pdf := gofpdf.New("P", "mm", "A4", "")
    13. pdf.AddPage()
    14. pdf.SetFont("Arial", "B", 16)
    15. // CellFormat(width, height, text, border, position after, align, fill, link, linkStr)
    16. pdf.CellFormat(190, 7, "Welcome to topgoer.com", "0", 0, "CM", false, 0, "")
    17. pdf.ImageOptions(
    18. "topgoer.png",
    19. 80, 20,
    20. 0, 0,
    21. false,
    22. gofpdf.ImageOptions{ImageType: "PNG", ReadDpi: true},
    23. 0,
    24. "",
    25. )