Skip to content

Commit

Permalink
Add AddtionnalInfo to Contact field
Browse files Browse the repository at this point in the history
  • Loading branch information
angelodlfrtr committed Jan 6, 2023
1 parent d2c31bc commit 3407e50
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
18 changes: 18 additions & 0 deletions contact.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ type Contact struct {
Name string `json:"name,omitempty" validate:"required,min=1,max=256"`
Logo []byte `json:"logo,omitempty"` // Logo byte array
Address *Address `json:"address,omitempty"`

// AddtionnalInfo to append after contact informations. You can use basic html here (bold, italic tags).
AddtionnalInfo []string `json:"additional_info,omitempty"`
}

// appendContactTODoc append the contact to the document
Expand Down Expand Up @@ -91,6 +94,21 @@ func (c *Contact) appendContactTODoc(
doc.pdf.MultiCell(70, 5, doc.encodeString(c.Address.ToString()), "0", "L", false)
}

// Addtionnal info
if c.AddtionnalInfo != nil {
doc.pdf.SetXY(x, doc.pdf.GetY())
doc.pdf.SetFontSize(SmallTextFontSize)
doc.pdf.SetXY(x, doc.pdf.GetY()+2)

for _, line := range c.AddtionnalInfo {
doc.pdf.SetXY(x, doc.pdf.GetY())
doc.pdf.MultiCell(70, 3, doc.encodeString(line), "0", "L", false)
}

doc.pdf.SetXY(x, doc.pdf.GetY())
doc.pdf.SetFontSize(BaseTextFontSize)
}

return doc.pdf.GetY()
}

Expand Down
5 changes: 5 additions & 0 deletions generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func TestNew(t *testing.T) {
City: "Paris",
Country: "France",
},
AddtionnalInfo: []string{"Cupcake: ipsum dolor"},
})

doc.SetCustomer(&Contact{
Expand All @@ -73,6 +74,10 @@ func TestNew(t *testing.T) {
City: "Brest",
Country: "France",
},
AddtionnalInfo: []string{
"Cupcake: ipsum dolor",
"Cupcake: ipsum dolo r",
},
})

for i := 0; i < 10; i++ {
Expand Down

0 comments on commit 3407e50

Please sign in to comment.