You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Nov 13, 2021. It is now read-only.
I need to generate a pdf document, and I have been using MultiCell to do so. However, I need the text to be justified, and MultiCell doesn't do so even when I specify that it should be justified.
Here's some code that can reproduce the issue:
package main
package main
import (
"github.com/jung-kurt/gofpdf"
)
const margin = 40
const lorem = "Lorem ipsum dolor sit amet consectetur adipiscing elit tellus rutrum suspendisse aliquet dignissim sem, faucibus tempor erat quisque vehicula sociosqu magna in praesent cursus habitant felis. Turpis ornare taciti habitant posuere inceptos vivamus viverra vulputate tempus convallis, molestie condimentum iaculis pellentesque leo ante est sed placerat curabitur vitae, suscipit mattis cursus fringilla lobortis litora sollicitudin justo nunc. Dignissim facilisi lectus natoque fermentum risus etiam integer mi iaculis nam ornare, augue porttitor blandit aliquet elementum sagittis faucibus habitasse et vitae."
func main() {
var pdf = gofpdf.New("P", "pt", "A4", "")
pdf.SetMargins(margin, margin, margin)
pdf.SetAutoPageBreak(true, margin)
pdf.AddPage()
pdf.SetFont("Arial", "", 15.0)
pdf.MultiCell(0.0, 15.0, lorem, "", "J", false)
pdf.OutputFileAndClose("test.pdf")
}
It looks like before UTF-8 fonts were supported, gofpdf did not support text justification (alignStr = "J") in CellFormat() or MultiCell(). Until we can fix up this block in CellFormat() it looks like the only way to justify text in MultiCell() is to use UTF-8 fonts. Here is your example with that change:
package main
import (
"fmt""os""github.com/jung-kurt/gofpdf"
)
constmargin=40constlorem="Lorem ipsum dolor sit amet consectetur adipiscing elit tellus rutrum suspendisse aliquet dignissim sem, faucibus tempor erat quisque vehicula sociosqu magna in praesent cursus habitant felis. Turpis ornare taciti habitant posuere inceptos vivamus viverra vulputate tempus convallis, molestie condimentum iaculis pellentesque leo ante est sed placerat curabitur vitae, suscipit mattis cursus fringilla lobortis litora sollicitudin justo nunc. Dignissim facilisi lectus natoque fermentum risus etiam integer mi iaculis nam ornare, augue porttitor blandit aliquet elementum sagittis faucibus habitasse et vitae."funcmain() {
varpdf=gofpdf.New("P", "pt", "A4", "")
pdf.AddUTF8Font("dejavu", "", "DejaVuSansCondensed.ttf")
pdf.SetMargins(margin, margin, margin)
pdf.SetAutoPageBreak(true, margin)
pdf.AddPage()
pdf.SetFont("dejavu", "", 15)
pdf.MultiCell(0.0, 15.0, lorem, "", "J", false)
err:=pdf.OutputFileAndClose("test2.pdf")
iferr!=nil {
fmt.Fprintf(os.Stderr, "%s\n", err)
}
}
I need to generate a pdf document, and I have been using MultiCell to do so. However, I need the text to be justified, and MultiCell doesn't do so even when I specify that it should be justified.
Here's some code that can reproduce the issue:
package main
It should generate the following PDF:
test.pdf
The text was updated successfully, but these errors were encountered: