Skip to content

Print PDF from HTML string #31

Description

@yasin-96

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>

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions