Package to open image or PDF, write text, save as PDF

Basically I want to write a simple invoice program for my small business, and I was planning on using an empty (already designed) invoice in some format (image/PDF/?), load it in, fill it with needed dates, amount etc, and then save it as a PDF (with a new file name). Does anyone have any suggestions for a package that can do that? The only thing that is “locked” is the output format (PDF)…

Preferably I would want free and open source software…

Use LaTeX.

Could you elaborate a little? I have heard of LaTeX (a long time ago), but barely remember anything about it…and what specific package are you talking about?

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.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.