gofpdf icon indicating copy to clipboard operation
gofpdf copied to clipboard

Print PDF from HTML string

Open yasin-96 opened this issue 1 year ago • 1 comments

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 avatar Sep 05 '23 14:09 yasin-96

Can anybody help with this ?

yasin-96 avatar Sep 09 '23 13:09 yasin-96