Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

could not locate "helveticaBB" #18

Closed
vladyslav2 opened this issue Jan 20, 2023 · 7 comments
Closed

could not locate "helveticaBB" #18

vladyslav2 opened this issue Jan 20, 2023 · 7 comments

Comments

@vladyslav2
Copy link

Problem

While working with this library I found an interesting case. If you create this markdown

### **Email:** issuer\_email

and when you try to convert, you will get an error:

➜  go run convert.go -i bad-markdown.md -o result.pdf 
2023/01/20 16:37:07 pdf.OutputFileAndClose() error:Pdf.OutputFileAndClose() error on result.pdf:could not locate "helveticaBB" among embedded core font definition files

Additional info
My understanding, gotopdf missing some fonts for italic headers

@mandolyte
Copy link
Collaborator

@vladyslav2 Since the gotopdf project is closed, do you have any ideas about how to address this (short of forking it)?

@vladyslav2
Copy link
Author

@mandolyte based on the error, it looks like gotopdf does have some default settings for various fonts (italic, bold, semi-bold and etc) and helveticaBB does not support all of those font variations. My best shot - check gotopdf settings and see if its configurable

@FrankStienhans2
Copy link

FrankStienhans2 commented Jun 19, 2024

Debugged it. The request into the SetFont method is "Arial" with Style "bb". This is being converted to "Hevetica" with style "bb". This is not defined as can be seen here: https://github.com/go-pdf/fpdf/tree/main/font_embed
Screenshot 2024-06-19 at 10 47 30 AM

This proves of course that the issue is either in blackfriday parser or in mdtopdf

@FrankStienhans2
Copy link

Not a fix but a functioning workaround:

func (r *PdfRenderer) processText(node *ast.Text) {
	currentStyle := r.cs.peek().textStyle
	if currentStyle.Style == "bb" { 
		currentStyle.Style = "b"
	}
	r.setStyler(currentStyle)

@jessp01
Copy link
Collaborator

jessp01 commented Jun 20, 2024

Hi @FrankStienhans2 ,

Thank you for the debugging info.

I'll take a look at it.
Please note that a while back, I migrated the project from blackfriday to gomarkdown which is actively maintained (see #40) but the issue is present when using that as well.

If you want a workaround pro tem, I'd suggest applying it in mdtopdf.go:setStyler() rather than in nodeProcessing.go:processText():

func (r *PdfRenderer) setStyler(s Styler) {
        if s.Style == "bb" {
            s.Style = "b"
        }
        r.Pdf.SetFont(s.Font, s.Style, s.Size)
        r.Pdf.SetTextColor(s.TextColor.Red, s.TextColor.Green, s.TextColor.Blue)
        r.Pdf.SetFillColor(s.FillColor.Red, s.FillColor.Green, s.FillColor.Blue)
}

@jessp01
Copy link
Collaborator

jessp01 commented Jun 20, 2024

So, the problem is here: https://github.com/mandolyte/mdtopdf/blob/master/nodeProcessing.go#L299

This can be easily solved with something like:

if entering {
                if ! strings.Contains(r.cs.peek().textStyle.Style, "b"){
                    r.cs.peek().textStyle.Style += "b"
                }
...

But, because the code (rightly) removes the "b" when entering is false, with this change, the sample MD input (## **Email**: issuer\_email) would result in Email being bold and the remainder of the header ("issuer_email") in "normal" style.
I can address this by checking whether the parent element is a header but I suppose the real question is why would one use ** (strong markup) within a header to begin with, considering the fact that headers are typically rendered in bold anyway, as they are (by default) in mdtopdf (see https://github.com/mandolyte/mdtopdf/blob/master/mdtopdf.go#L154). Could you please tell me what your expectation is for such an input?

Cheers,

@Xanvial
Copy link

Xanvial commented Jul 3, 2024

Hello, I encountered similar error,
for me the expectation is, it should ignore the strong markup. So will print as a header only.

For now I need to manually remove the ** markdown if it's exist inside a header

@jessp01 jessp01 closed this as completed in d18918d Jul 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants