Golang Program to Create PDF File Using FPDF Library and Save it inside PC Full Tutorial For Beginners

  • Post author:
  • Post category:Go
  • Post comments:0 Comments

 

 

Installation 

 

To install the package on your system, run

 

go get github.com/jung-kurt/gofpdf

 

 

 

Usage

 

 

pdf := gofpdf.New("P", "mm", "A4", "")
pdf.AddPage()
pdf.SetFont("Arial", "B", 16)
pdf.Cell(40, 10, "Hello, world")
err := pdf.OutputFileAndClose("hello.pdf")

 

 

app.go

 

 

package main

import (
    "github.com/jung-kurt/gofpdf"
)

func main() {
    pdf := gofpdf.New(gofpdf.OrientationPortrait, "mm", "A4", "")
    pdf.AddPage()
    pdf.SetFont("Arial", "B", 16)
    pdf.Cell(40, 10, "Hello World!")
    fileStr := example.Filename("basic")
    err := pdf.OutputFileAndClose(fileStr)
    example.Summary(err, fileStr)
}

 

 

Now to run the file simply

 

 

go run app.go

 

Leave a Reply