unidoc / unipdf

Golang PDF library for creating and processing PDF files (pure go)
https://unidoc.io
Other
2.46k stars 250 forks source link

[FEATURE] Support for html styles in StyledParagraph #512

Closed kevinrathgeber closed 1 year ago

kevinrathgeber commented 1 year ago

Is your feature request related to a problem? Please describe. We have inputs that allow the user to add some basic styles (ie. bold, italic, underline) to their text which we then end up rendering in a PDF. Currently, to render in the PDF, we're removing all html tags and just rendering as plaintext but this obviously removes emphasis and other stylistic things that the user intentionally included in their response. It would be nice if we could easily maintain these styles when writing to the PDF.

I understand this is likely out of the scope of the purpose of this library, but figured this may start the discussion about how to best approach this situation to get our desired result.

Describe the solution you'd like Given an HTML string like <p><strong>This is bold text.</strong></p>, the PDF would apply the bold style to this text.

Describe alternatives you've considered Another option we've considered (and probably the route we'll need to go) is to write this section of the PDF word-by-word in a StyledParagraph and detect the beginning and the end of the relevant style tags and apply the corresponding style to the font.

I am definitely open to alternatives if anyone has thoughts.

Additional context No additional context to share, but let me know if anything would be helpful!

github-actions[bot] commented 1 year ago

Welcome! Thanks for posting your first issue. The way things work here is that while customer issues are prioritized, other issues go into our backlog where they are assessed and fitted into the roadmap when suitable. If you need to get this done, consider buying a license which also enables you to use it in your commercial products. More information can be found on https://unidoc.io/

sampila commented 1 year ago

Hi @kevinrathgeber,

We have a function of https://github.com/unidoc/unipdf-examples/tree/master/templates, probably that can help to solve your problems.

kevinrathgeber commented 1 year ago

Hi @kevinrathgeber,

We have a function of https://github.com/unidoc/unipdf-examples/tree/master/templates, probably that can help to solve your problems.

Oh wow, this is awesome. Thank you so much! I'll try it out.

Also not sure if it matters, but my company does have a unipdf license

kevinrathgeber commented 1 year ago

Closing this out because it looks like this can be done already. Thanks again @sampila!