Here is the the way I have decided to move forward, for future reference, and in case it helps any one else:
Step 1 : I will start by loading and image of an empty invoice, add some texts to it and save the image with a new file name using code like his:
package main
import (
"github.com/gotk3/gotk3/cairo"
"github.com/gotk3/gotk3/gdk"
"github.com/gotk3/gotk3/gtk"
)
func main () {
// Load the image
image, err :=gdk.PixbufNewFromFile("/home/per/temp/test.png")
if err!=nil {
panic(err)
}
// Get the image format
var format cairo.Format
if image.GetHasAlpha () {
format = cairo.FORMAT_ARGB32
} else {
format = cairo.FORMAT_RGB24
}
// Create a surface to draw on
width := image.GetWidth ()
height := image.GetHeight()
surface := cairo.CreateImageSurface (format, width, height)
if surface==nil {
panic("surface is nil")
}
cr := cairo.Create(surface)
// Load the image into the surface
gtk.GdkCairoSetSourcePixBuf(cr,image,0,0)
cr.Paint()
// Write text
cr.SetSourceRGB(0,0,0)
cr.SetFontSize(20)
cr.SelectFontFace("tahoma",cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL)
cr.MoveTo(100.5,100)
cr.ShowText("test")
// Save the image
surface.WriteToPNG("/home/per/temp/test2.png")
// Clean up
surface = nil
cr = nil
}
Step 2 : I will take the image created in step 1 and put it in a new PDF using the gofpdf package:
package main
import (
"github.com/jung-kurt/gofpdf"
)
func main() {
pdf := gofpdf.New("P", "mm", "A4", "")
pdf.AddPage()
pdf.SetFont("Arial", "B", 16)
pdf.Cell(40, 10, "Hello world!!!")
pdf.Image("invoice.png",0,50,100,100,false,"",0,"")
err := pdf.OutputFileAndClose("hello.pdf")
if err!=nil {
panic(err)
}
}
This is good enough for me and it seems to work.