Open Meowgician opened 5 years ago
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"
)
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.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")
if err != 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