phpdave11 / gofpdf

A PDF document generator with high level support for text, drawing and images
http://godoc.org/github.com/phpdave11/gofpdf
MIT License
211 stars 42 forks source link

Print PDF from HTML string #31

Open yasin-96 opened 1 year ago

yasin-96 commented 1 year ago

Hey` guys,

I am trying to figure out why my code is not working as expected. I have markdown source code, which I am converting with: https://github.com/gomarkdown/markdown It is giving me some html string, which I am trying to print to a PDF, but when I print it to a PDF the HTML tags are ignored and just plaintext is printed.

My code:

_, lineHt := pdf.GetFontSize()
html := pdf.HTMLBasicNew()
convertedHTML := convertMarkdown(subchapter.Content)
println(string(convertedHTML))
html.Write(lineHt, string(convertedHTML))
err := pdf.OutputFileAndClose(fmt.Sprintf("%s.pdf", course.Name))
func convertMarkdown(subchapterContent string) []byte {
    extensions := parser.CommonExtensions | parser.OrderedListStart | parser.NoEmptyLineBeforeBlock
    p := parser.NewWithExtensions(extensions)
    doc := p.Parse([]byte(subchapterContent))

    htmlFlags := html.CommonFlags | html.HrefTargetBlank
    opts := html.RendererOptions{Flags: htmlFlags}
    renderer := html.NewRenderer(opts)

    return markdown.Render(doc, renderer)
}

The convert returns me this string

<h2>Chapter outcomes</h2>

<p>At the end of this page you should be able to:</p>

<ul>
<li>Explain how the Cloud Native Computing Foundation (CNCF) defines the Cloud Native terms and their core characteristics.</li>
<li>Describe monolith vs. microservices architecture approaches with examples as well as the benefits and drawbacks of both approaches.</li>
<li>Describe different autoscaling options in Cloud Native environments.</li>
<li>Describe the concept and benefits of serverless computing.</li>
<li>Explain community and governance</li>
<li>Explain the roles and personas that exist within Cloud Native environments and their corresponding tasks?</li>
<li>Describe which open standards are available in Cloud Native world and what they are used for?</li>
</ul>
yasin-96 commented 1 year ago

Can anybody help with this ?