Can’t wrap long text with no whitespaces in Visualforce page rendered as PDF

pdfvisualforce

I have a table created in Visualforce page and rendered as a PDF. There are columns where long texts (with no whitespaces) can exist. However, it seems impossible to make these texts to wrap so that it doesnt overflow to the next column. I have tried different CSS properties such as below but none seem to work

.my-style {
   white-space: normal;
   word-wrap: break-word;
   overflow-wrap: break-word;
}

My problem is similar to this question Wrap a long line of text that is without spaces in visualforce rendered as pdf and from some searching, this seems to be a known issue when rendering a Visualforce as PDF before. But I wanted to know if this is something that has been fixed already / has a work around?

Best Answer

Salesforce uses the Flying Saucer library to convert Visualforce pages to PDF.

Flying Saucer only supports up to CSS 2.1.

word-wrap and overflow-wrap were introduced in CSS 3, and are thus not supported.

white-space: normal appears to be the default, was introduced in CSS 2.1, and it does wrap words, but it requires whitespace.

If you don't have whitespace, there's nothing you can do with CSS to make your PDF render the way you want it to.

About the only thing I can think of here would be to choose a moderate number of letters that you can safely display in a column (without overflowing), and then process your text in a custom controller (or controller extension) to insert line breaks after every X characters.