Question

I am trying to convert HTML to PDF with jsPDF. But since I want every word to in the exact location as in HTML, I wrapped every word in <span>s. Here I have a font tag (not generated by my code) containing a bunch of spans:

<font><span>Hello</span>&nbsp;<span>wrap</span>&nbsp;<span>....</font>

However when I do this it seems to break the default wordwrapping as you can see in here.

How can I fix this?

Was it helpful?

Solution

This is because default display is inline. If you use inline-block it will wrap as you expect:

See this jsfiddle

The only change is to the CSS:

span
{
    display:inline-block;    
}

You may want to create a new class for this (e.g. wordWrapSpan) rather than changing default behaviour of span.

OTHER TIPS

You can also use:

style word-wrap: break-word;

.font{ word-wrap: break-word; } See this fiddle Fiddle

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top