Confusing output
laice opened this issue · comments
Hi, I'm having a hard time understanding the output I'm getting - mainly the way newlines and page breaks work. Why does this page break to the next page? Why does it seem like sometimes newline works and sometimes it doesn't? I've also tried multiple calls to WriteAligned instead of concatenating strings, but I still get confusing output with page breaks that I don't understand. Thanks for any advice.
`
pdf := gofpdf.NewCustom(&gofpdf.InitType{
UnitStr: "in",
Size: gofpdf.SizeType{Wd: 1, Ht: 1.5},
})
pdf.AddUTF8Font("Agency FB", "", "./agency-fb.ttf")
pdf.SetMargins(0,0.25,0)
pdf.SetFont("Agency FB", "", 9)
pdf.AddPageFormat("P", gofpdf.SizeType{Wd:1, Ht: 1.5})
re, err := regexp.Compile(`Vape Pen [0-9]*`)
qslog.Error(err, "Error compiling Vape Pen regex")
pdf.WriteAligned(1, 0.155, strain + fmt.Sprintf("\nTotal THC= %smg\nCBD = %smg", thc, cbd), "C")
pdf.SetFont("Agency FB", "",10)
err = pdf.OutputFileAndClose(*metrcPtr + ".pdf")
qslog.Error(err, "Unable to generate pdf")
`
I'm having a hard time understanding the output I'm getting - mainly the way newlines and page breaks work.
I don't understand your results either. When I ran your code (using the Deja Vu Font instead of the agency font which I don't have) the newlines are placed right where they should be. You may want to try the Deja Vu font to see if there is a change.
Unfortunately unless I'm mistaken the Deja Vu fonts don't offer the same thin styled font that Agency FB is, it allows fitting more information in the same space, which is at a premium in my use case. Thank you for making me aware this is part of the problem space, however
I did find a Deja Vu Serif Condensed, but it's not quite small enough - for example the Total THC line fits on one line in Agency FB. Is there something special about these extra thin fonts? Guess I'll look into that. Also, I guess newlines are being made into page breaks? Here's my output with the same code but the font changed to Deja Vu Serif Condensed
Is there something special about these extra thin fonts?
I wouldn't think so, but it's worth a look.
Also, I guess newlines are being made into page breaks?
No. I think because of the really small page size you are running into the 2 cm default page break margin. Note that pdf.SetMargins()
only sets the left, top, and right margins. The bottom margin is specified separately because it is used for automatic page breaking. See SetAutoPageBreak()
. You may want to disable automatic page breaks entirely and keep track of positions manually.
If you are looking for text that is very thin, you may want to try using the TransformScaleY()
method to stretch text vertically.
Please reopen if this is still an issue