Skip to content

Commit

Permalink
Use github.com/go-pdf/fpdf instead of github.com/jung-kurt/gofpdf sin…
Browse files Browse the repository at this point in the history
…ce the later is not maintained anymore

sorry if there's a better alternative
  • Loading branch information
take committed Jun 22, 2022
1 parent 29665f1 commit 09c7f24
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Golang invoice generator

A super fast golang package to generate invoices, delivery notes and quotations as pdf
using https://github.com/jung-kurt/gofpdf.
using https://github.com/go-pdf/fpdf.

## Download from Github

Expand Down
4 changes: 2 additions & 2 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import (
"fmt"
"time"

"github.com/jung-kurt/gofpdf"
"github.com/go-pdf/fpdf"
"github.com/leekchan/accounting"
"github.com/shopspring/decimal"
)

// Build pdf document from data provided
func (doc *Document) Build() (*gofpdf.Fpdf, error) {
func (doc *Document) Build() (*fpdf.Fpdf, error) {
// Validate document data
err := doc.Validate()
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions contact.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
b64 "encoding/base64"
"image"

"github.com/jung-kurt/gofpdf"
"github.com/go-pdf/fpdf"
)

// Contact contact a company informations
Expand Down Expand Up @@ -36,12 +36,12 @@ func (c *Contact) appendContactTODoc(
_, format, _ := image.DecodeConfig(bytes.NewReader(*c.Logo))

// Register image in pdf
imageInfo := doc.pdf.RegisterImageOptionsReader(fileName, gofpdf.ImageOptions{
imageInfo := doc.pdf.RegisterImageOptionsReader(fileName, fpdf.ImageOptions{
ImageType: format,
}, ioReader)

if imageInfo != nil {
var imageOpt gofpdf.ImageOptions
var imageOpt fpdf.ImageOptions
imageOpt.ImageType = format
doc.pdf.ImageOptions(fileName, doc.pdf.GetX(), y, 0, 30, false, imageOpt, 0, "")
doc.pdf.SetY(y + 30)
Expand Down
12 changes: 7 additions & 5 deletions document.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package generator

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

// Document define base document
type Document struct {
pdf *gofpdf.Fpdf
pdf *fpdf.Fpdf

Options *Options `json:"options,omitempty"`
Header *HeaderFooter `json:"header,omitempty"`
Expand All @@ -25,13 +27,13 @@ type Document struct {
Discount *Discount `json:"discount,omitempty"`
}

// Pdf returns the underlying *gofpdf.Fpdf used to build document
func (doc *Document) Pdf() *gofpdf.Fpdf {
// Pdf returns the underlying *fpdf.Fpdf used to build document
func (doc *Document) Pdf() *fpdf.Fpdf {
return doc.pdf
}

// SetUnicodeTranslator to use
// See https://pkg.go.dev/github.com/jung-kurt/gofpdf#UnicodeTranslator
// See https://pkg.go.dev/github.com/go-pdf/fpdf#UnicodeTranslator
func (doc *Document) SetUnicodeTranslator(fn UnicodeTranslateFunc) {
doc.Options.UnicodeTranslateFunc = fn
}
Expand Down
6 changes: 3 additions & 3 deletions examples/iso_8859_2_cp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"io/ioutil"
"os"

"github.com/angelodlfrtr/go-invoice-generator"
"github.com/jung-kurt/gofpdf"
generator "github.com/angelodlfrtr/go-invoice-generator"
"github.com/go-pdf/fpdf"
)

func main() {
Expand All @@ -18,7 +18,7 @@ func main() {
// Set up translator
func() {
trReader, _ := os.Open("./iso-8859-2.map")
unicodeTranslator, _ := gofpdf.UnicodeTranslator(trReader)
unicodeTranslator, _ := fpdf.UnicodeTranslator(trReader)
doc.SetUnicodeTranslator(unicodeTranslator)
}()

Expand Down
4 changes: 2 additions & 2 deletions generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package generator

import (
"github.com/creasty/defaults"
"github.com/jung-kurt/gofpdf"
"github.com/go-pdf/fpdf"
)

// New return a new documents with provided types and defaults
Expand All @@ -15,7 +15,7 @@ func New(docType string, options *Options) (*Document, error) {
Type: docType,
}

doc.pdf = gofpdf.New("P", "mm", "A4", "")
doc.pdf = fpdf.New("P", "mm", "A4", "")
doc.Options.UnicodeTranslateFunc = doc.pdf.UnicodeTranslatorFromDescriptor("")

return doc, nil
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.17

require (
github.com/creasty/defaults v1.5.2
github.com/jung-kurt/gofpdf v1.16.2
github.com/go-pdf/fpdf v0.6.0
github.com/leekchan/accounting v0.3.1
github.com/shopspring/decimal v1.3.1
gopkg.in/go-playground/validator.v9 v9.31.0
Expand All @@ -15,6 +15,6 @@ require (
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/pkg/errors v0.8.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
)
14 changes: 10 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
github.com/boombuler/barcode v1.0.0/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
github.com/boombuler/barcode v1.0.1/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I=
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
github.com/creasty/defaults v1.5.2 h1:/VfB6uxpyp6h0fr7SPp7n8WJBoV8jfxQXPCnkVSjyls=
github.com/creasty/defaults v1.5.2/go.mod h1:FPZ+Y0WNrbqOVw+c6av63eyHUAl6pMHZwqLPvXUZGfY=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-pdf/fpdf v0.6.0 h1:MlgtGIfsdMEEQJr2le6b/HNr1ZlQwxyWr77r2aj2U/8=
github.com/go-pdf/fpdf v0.6.0/go.mod h1:HzcnA+A23uwogo0tp9yU+l3V+KXhiESpt1PMayhOh5M=
github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU=
github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs=
github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/jYrnRPArHwAcmLoJZxyho=
github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA=
github.com/jung-kurt/gofpdf v1.0.0/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes=
github.com/jung-kurt/gofpdf v1.16.2 h1:jgbatWHfRlPYiK85qgevsZTHviWXKwB1TTiKdz5PtRc=
github.com/jung-kurt/gofpdf v1.16.2/go.mod h1:1hl7y57EsiPAkLbOwzpzqgx1A30nQCk/YmFV8S2vmK0=
github.com/leekchan/accounting v0.3.1 h1:6cIBKG9QngR6tuVV+mWjzcxsJDnoegrc70Ntb3MFqYM=
github.com/leekchan/accounting v0.3.1/go.mod h1:3timm6YPhY3YDaGxl0q3eaflX0eoSx3FXn7ckHe4tO0=
github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
github.com/lib/pq v1.0.0 h1:X5PMW56eZitiTeO7tKzZxFCSpbFZJtkMMooicw2us9A=
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/phpdave11/gofpdi v1.0.7/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/phpdave11/gofpdf v1.4.2/go.mod h1:zpO6xFn9yxo3YLyMvW8HcKWVdbNqgIfOOp2dXMnm1mY=
github.com/phpdave11/gofpdi v1.0.12/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI=
github.com/phpdave11/gofpdi v1.0.13/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/ruudk/golang-pdf417 v0.0.0-20181029194003-1af4ab5afa58/go.mod h1:6lfFZQK844Gfx8o5WFuvpxWRwnSoipWe/p622j1v06w=
github.com/ruudk/golang-pdf417 v0.0.0-20201230142125-a7e3863a1245/go.mod h1:pQAZKsJ8yyVxGRWYNEm9oFB8ieLgKFnamEyDmSA0BRk=
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
Expand All @@ -32,6 +37,7 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/image v0.0.0-20190910094157-69e4b8554b2a/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20210607152325-775e3b0c77b9/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down
4 changes: 2 additions & 2 deletions header_footer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"

"github.com/creasty/defaults"
"github.com/jung-kurt/gofpdf"
"github.com/go-pdf/fpdf"
)

// HeaderFooter define header or footer informations on document
Expand All @@ -18,7 +18,7 @@ type HeaderFooter struct {
type fnc func()

// ApplyFunc allow user to apply custom func
func (hf *HeaderFooter) ApplyFunc(pdf *gofpdf.Fpdf, fn fnc) {
func (hf *HeaderFooter) ApplyFunc(pdf *fpdf.Fpdf, fn fnc) {
pdf.SetHeaderFunc(fn)
}

Expand Down

0 comments on commit 09c7f24

Please sign in to comment.