Skip to content
This repository was archived by the owner on Nov 13, 2021. It is now read-only.

Commit d0584cb

Browse files
committed
Merge branch 'wmatusiak-WordSpacing'
2 parents 5e8bff4 + 10d79b6 commit d0584cb

3 files changed

Lines changed: 12 additions & 0 deletions

File tree

fpdf.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,6 +1897,11 @@ func (f *Fpdf) Text(x, y float64, txtStr string) {
18971897
f.out(s)
18981898
}
18991899

1900+
// SetWordSpacing sets spacing between words of following text
1901+
func (f *Fpdf) SetWordSpacing(space float64) {
1902+
f.out(sprintf("%.5f Tw", space*f.k))
1903+
}
1904+
19001905
// SetAcceptPageBreakFunc allows the application to control where page breaks
19011906
// occur.
19021907
//

fpdf_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,13 @@ func ExampleFpdf_WriteAligned() {
799799
pdf.WriteAligned(0, 35, "This text is aligned Center", "C")
800800
pdf.Ln(35)
801801
pdf.WriteAligned(0, 35, "This text is aligned Right", "R")
802+
pdf.Ln(35)
803+
line := "This text fill line using word spacing. This can by used to write justified text"
804+
leftMargin, _, rightMargin, _ := pdf.GetMargins()
805+
pageWidth, _ := pdf.GetPageSize()
806+
pageWidth -= leftMargin + rightMargin
807+
pdf.SetWordSpacing((pageWidth - pdf.GetStringWidth(line)) / float64(strings.Count(line, " ")))
808+
pdf.WriteAligned(pageWidth, 35, line, "L")
802809
fileStr := example.Filename("Fpdf_WriteAligned")
803810
err := pdf.OutputFileAndClose(fileStr)
804811
example.Summary(err, fileStr)
58 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)