Initial commit
This commit is contained in:
commit
58db7b7465
|
|
@ -0,0 +1,3 @@
|
||||||
|
mkinvoice
|
||||||
|
makefont
|
||||||
|
*.pdf
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
mkinvoice will generate a PDF invoice from a YAML-file
|
||||||
|
|
||||||
|
It is the by-result of learning the Golang language, but with the
|
||||||
|
purpose to generate PDF-Invoices for nbit Informatik GmbH
|
||||||
|
|
||||||
|
Font File can be generated on http://www.fpdf.org/makefont/
|
||||||
|
|
||||||
|
Joerg Lehmann, April 2020
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
{"Tp":"TrueType","Name":"DejaVuSans-Bold","Desc":{"Ascent":760,"Descent":-240,"CapHeight":760,"Flags":32,"FontBBox":{"Xmin":-1069,"Ymin":-415,"Xmax":1975,"Ymax":1175},"ItalicAngle":0,"StemV":120,"MissingWidth":600},"Up":-20,"Ut":44,"Cw":[600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,348,456,521,838,696,1002,872,306,457,457,523,838,380,415,380,365,696,696,696,696,696,696,696,696,696,696,400,400,838,838,838,580,1000,774,762,734,830,683,683,821,837,372,372,775,637,995,837,850,733,850,770,720,682,812,774,1103,771,724,725,457,365,457,838,500,500,675,716,593,716,678,435,716,712,343,343,665,343,1042,712,687,716,716,493,595,478,712,652,924,645,652,582,712,365,712,838,600,696,600,380,435,657,1000,500,500,500,1440,720,412,1167,600,725,600,600,380,380,657,657,639,500,1000,500,1000,595,412,1094,600,582,724,348,456,696,696,636,696,365,500,500,1000,564,646,838,415,1000,500,500,838,438,438,500,736,636,380,500,438,564,646,1035,1035,1035,580,774,774,774,774,774,774,1085,734,683,683,683,683,372,372,372,372,838,837,850,850,850,850,850,838,850,812,812,812,812,724,738,719,675,675,675,675,675,675,1048,593,678,678,678,678,343,343,343,343,687,712,687,687,687,687,687,838,687,712,712,712,712,652,716,652],"Enc":"cp1252","Diff":"","File":"DejaVuSans-Bold.z","Size1":0,"Size2":0,"OriginalSize":705684,"N":0,"DiffN":0}
|
||||||
Binary file not shown.
|
|
@ -0,0 +1 @@
|
||||||
|
{"Tp":"TrueType","Name":"DejaVuSans","Desc":{"Ascent":760,"Descent":-240,"CapHeight":760,"Flags":32,"FontBBox":{"Xmin":-1021,"Ymin":-463,"Xmax":1793,"Ymax":1232},"ItalicAngle":0,"StemV":70,"MissingWidth":600},"Up":-20,"Ut":44,"Cw":[600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,600,318,401,460,838,636,950,780,275,390,390,500,838,318,361,318,337,636,636,636,636,636,636,636,636,636,636,337,337,838,838,838,531,1000,684,686,698,770,632,575,775,752,295,295,656,557,863,748,787,603,787,695,635,611,732,684,989,685,611,685,390,337,390,838,500,500,613,635,550,635,615,352,635,634,278,278,579,278,974,634,612,635,635,411,521,392,634,592,818,592,592,525,636,337,636,838,600,636,600,318,352,518,1000,500,500,500,1342,635,400,1070,600,685,600,600,318,318,518,518,590,500,1000,500,1000,521,400,1023,600,525,611,318,401,636,636,636,636,337,500,500,1000,471,612,838,361,1000,500,500,838,401,401,500,636,636,318,500,401,471,612,969,969,969,531,684,684,684,684,684,684,974,698,632,632,632,632,295,295,295,295,775,748,787,787,787,787,787,838,787,732,732,732,732,611,605,630,613,613,613,613,613,613,982,550,615,615,615,615,278,278,278,278,612,634,612,612,612,612,612,838,612,634,634,634,634,592,635,592],"Enc":"cp1252","Diff":"","File":"DejaVuSans.z","Size1":0,"Size2":0,"OriginalSize":757076,"N":0,"DiffN":0}
|
||||||
Binary file not shown.
|
|
@ -0,0 +1,22 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/jung-kurt/gofpdf"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
pdf := gofpdf.New("P", "mm", "A4", "")
|
||||||
|
|
||||||
|
pdf.SetFontLocation("fonts")
|
||||||
|
errs := gofpdf.MakeFont("/usr/share/fonts/dejavu/DejaVuSans.ttf", "/home/joerg/go/src/github.com/jung-kurt/gofpdf/font/cp1252.map", "fonts", nil, true)
|
||||||
|
if errs != nil {
|
||||||
|
fmt.Println(errs)
|
||||||
|
}
|
||||||
|
errs2 := gofpdf.MakeFont("/usr/share/fonts/dejavu/DejaVuSans-Bold.ttf", "/home/joerg/go/src/github.com/jung-kurt/gofpdf/font/cp1252.map", "fonts", nil, true)
|
||||||
|
if errs2 != nil {
|
||||||
|
fmt.Println(errs)
|
||||||
|
}
|
||||||
|
pdf.AddFont("DejaVuSans", "", "DejaVuSans.json")
|
||||||
|
pdf.AddFont("DejaVuSans-Bold", "", "DejaVuSans-Bold.json")
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,96 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/jung-kurt/gofpdf"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Adress struct {
|
||||||
|
lines []string
|
||||||
|
}
|
||||||
|
|
||||||
|
type Item struct {
|
||||||
|
text string
|
||||||
|
count float64
|
||||||
|
price float64
|
||||||
|
}
|
||||||
|
|
||||||
|
type InvoiceData struct {
|
||||||
|
invoice_number string
|
||||||
|
invoice_date string
|
||||||
|
address Adress
|
||||||
|
items []Item
|
||||||
|
invoice_total_net float64
|
||||||
|
invoice_mwst float64
|
||||||
|
invoice_total float64
|
||||||
|
}
|
||||||
|
|
||||||
|
/* global variable declaration */
|
||||||
|
var pdf *gofpdf.Fpdf
|
||||||
|
var y_pos float64
|
||||||
|
var invoice_data InvoiceData
|
||||||
|
const margin_top = 7
|
||||||
|
const line_spacing = 4
|
||||||
|
const tabstop_left = 20
|
||||||
|
const tabstop_header_label = 80
|
||||||
|
const tabstop_header_value = 100
|
||||||
|
const tabstop_address = 10
|
||||||
|
const tabstop_count = 10
|
||||||
|
const tabstop_price = 10
|
||||||
|
const tabstop_total = 10
|
||||||
|
|
||||||
|
func ReadInvoiceData(filename string) {
|
||||||
|
invoice_data.invoice_number = "1"
|
||||||
|
invoice_data.invoice_date = "01.01.2021"
|
||||||
|
invoice_data.address = Adress{ []string{"Jörg Lehmann", "Kirchweg 2", "3510 Konolfingen" }}
|
||||||
|
invoice_data.items = []Item{ Item{ "Item 1",1,10 }, Item{"Text only",0,0 } }
|
||||||
|
invoice_data.invoice_total_net = 100
|
||||||
|
invoice_data.invoice_mwst = 10
|
||||||
|
invoice_data.invoice_total = 110
|
||||||
|
}
|
||||||
|
|
||||||
|
func WriteText(x float64, y float64, text string, alignStr ...string) {
|
||||||
|
align := "LT"
|
||||||
|
if len(alignStr) > 0 {
|
||||||
|
align = alignStr[0]
|
||||||
|
}
|
||||||
|
pdf.SetXY(x, y)
|
||||||
|
pdf.CellFormat(0, 10, text, "", 0, align, false, 0, "")
|
||||||
|
}
|
||||||
|
|
||||||
|
func SetupInvoice() {
|
||||||
|
pdf = gofpdf.New("P", "mm", "A4", "")
|
||||||
|
pdf.SetMargins(0, 0, 0)
|
||||||
|
pdf.SetFontLocation("fonts")
|
||||||
|
pdf.AddFont("Dejavusans", "", "DejaVuSans.json")
|
||||||
|
pdf.AddFont("Dejavusans-Bold", "", "DejaVuSans-Bold.json")
|
||||||
|
pdf.SetFont("Dejavusans", "", 9)
|
||||||
|
}
|
||||||
|
|
||||||
|
func PrintPageHeader(firstPage bool) {
|
||||||
|
pdf.AddPage()
|
||||||
|
y_pos = margin_top
|
||||||
|
pdf.SetFont("Dejavusans-Bold", "", 9)
|
||||||
|
WriteText(tabstop_left, y_pos, "nbit Informatik GmbH")
|
||||||
|
pdf.SetFont("Dejavusans", "", 9)
|
||||||
|
WriteText(tabstop_header_label, y_pos, "Tel.")
|
||||||
|
WriteText(tabstop_header_value, y_pos, "+41 31 792 00 40")
|
||||||
|
y_pos = y_pos + line_spacing
|
||||||
|
WriteText(tabstop_left, y_pos, "Kirchweg 2")
|
||||||
|
WriteText(tabstop_header_label, y_pos, "EMal")
|
||||||
|
WriteText(tabstop_header_value, y_pos, "joerg.lehmann@nbit.ch")
|
||||||
|
y_pos = y_pos + line_spacing
|
||||||
|
WriteText(tabstop_left, y_pos, "3510 Konolfingen")
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
SetupInvoice()
|
||||||
|
PrintPageHeader(true)
|
||||||
|
|
||||||
|
err := pdf.OutputFileAndClose("hello.pdf")
|
||||||
|
if err == nil {
|
||||||
|
fmt.Printf("Successfully created invoice\n")
|
||||||
|
} else {
|
||||||
|
fmt.Printf("Error: %v\n", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue