# README
Golang invoice generator
A super fast golang package to generate invoices, delivery notes and quotations as pdf using https://github.com/jung-kurt/gofpdf.
Download from Github
go get -u github.com/angelodlfrtr/go-invoice-generator
Exemple output
Quick start
package main
import (
"io/ioutil"
"testing"
generator "github.com/angelodlfrtr/go-invoice-generator"
)
func TestNew(t *testing.T) {
doc, _ := generator.New(generator.Invoice, &generator.Options{
TextTypeInvoice: "FACTURE",
AutoPrint: true,
})
doc.SetHeader(&generator.HeaderFooter{
Text: "<center>Cupcake ipsum dolor sit amet bonbon. I love croissant cotton candy. Carrot cake sweet I love sweet roll cake powder.</center>",
Pagination: true,
})
doc.SetFooter(&generator.HeaderFooter{
Text: "<center>Cupcake ipsum dolor sit amet bonbon. I love croissant cotton candy. Carrot cake sweet I love sweet roll cake powder.</center>",
Pagination: true,
})
doc.SetRef("testref")
doc.SetVersion("someversion")
doc.SetDescription("A description")
doc.SetNotes("I love croissant cotton candy. Carrot cake sweet I love sweet roll cake powder! I love croissant cotton candy. Carrot cake sweet I love sweet roll cake powder! I love croissant cotton candy. Carrot cake sweet I love sweet roll cake powder! I love croissant cotton candy. Carrot cake sweet I love sweet roll cake powder! ")
doc.SetDate("02/03/2021")
doc.SetPaymentTerm("02/04/2021")
logoBytes, _ := ioutil.ReadFile("./example_logo.png")
doc.SetCompany(&generator.Contact{
Name: "Test Company",
Logo: &logoBytes,
Address: &generator.Address{
Address: "89 Rue de Brest",
Address2: "Appartement 2",
PostalCode: "75000",
City: "Paris",
Country: "France",
},
})
doc.SetCustomer(&generator.Contact{
Name: "Test Customer",
Address: &generator.Address{
Address: "89 Rue de Paris",
PostalCode: "29200",
City: "Brest",
Country: "France",
},
})
for i := 0; i < 3; i++ {
doc.AppendItem(&generator.Item{
Name: "Cupcake ipsum dolor sit amet bonbon, coucou bonbon lala jojo, mama titi toto",
Description: "Cupcake ipsum dolor sit amet bonbon, Cupcake ipsum dolor sit amet bonbon, Cupcake ipsum dolor sit amet bonbon",
UnitCost: "99876.89",
Quantity: "2",
Tax: &Tax{
Percent: "20",
},
})
}
doc.AppendItem(&generator.Item{
Name: "Test",
UnitCost: "99876.89",
Quantity: "2",
Tax: &Tax{
Amount: "89",
},
Discount: &Discount{
Percent: "30",
},
})
doc.AppendItem(&generator.Item{
Name: "Test",
UnitCost: "3576.89",
Quantity: "2",
Discount: &Discount{
Percent: "50",
},
})
doc.AppendItem(&generator.Item{
Name: "Test",
UnitCost: "889.89",
Quantity: "2",
Discount: &Discount{
Amount: "234.67",
},
})
doc.SetDefaultTax(&generator.Tax{
Percent: "10",
})
// doc.SetDiscount(&generator.Discount{
// Percent: "90",
// })
doc.SetDiscount(&generator.Discount{
Amount: "1340",
})
pdf, err := doc.Build()
if err != nil {
log.Fatal(err)
}
err = pdf.OutputFileAndClose("out.pdf")
if err != nil {
log.Fatal(err)
}
}
License
This SDK is distributed under the Apache License, Version 2.0, see LICENSE and NOTICE for more information.
# Constants
BaseMargin define base margin used in documents.
BaseMarginTop define base margin top used in documents.
DeliveryNote define the "delievry note" document type.
HeaderMarginTop define base header margin top used in documents.
Invoice define the "invoice" document type.
InvoiceMonthly define the "invoice monthly" document type.
ItemColDiscountOffset ...
ItemColNameOffset ...
ItemColQuantityOffset ...
ItemColTaxOffset ...
ItemColTotalHTOffset ...
ItemColTotalTTCOffset ...
ItemColUnitPriceOffset ...
MaxPageHeight define the maximum height for a single page.
Quotation define the "quotation" document type.
# Variables
BaseTextColor define the base color used for text in document.
BaseTextFontSize define the base font size for text in document.
DarkBgColor define the grey background color used for text in document.
ExtraSmallTextFontSize define the extra small font size for text in document.
GreyBgColor define the grey background color used for text in document.
GreyTextColor define the base color used for text in document.
LargeTextFontSize define the large font size for text in document.
SmallTextFontSize define the small font size for text in document.
# Structs
Address represent an address.
Contact contact a company informations.
Discount define discount as percent or fixed amount.
Document define base document.
HeaderFooter define header or footer informations on document.
Item represent a 'product' or a 'service'.
No description provided by the author
Options for Document.
Tax define tax as percent or fixed amount.