openhtmltopdf
openhtmltopdf copied to clipboard
Prevent line break after comma / dot / special characters
Hi, Its work fine when tested in https://sandbox.openhtmltopdf.com/?file=page-features.htm But, it doesn't work in my project.
Text example: There are 10 apples which cost $150,000 and 20 pineapples which cost $288,888.
Expected result: There are 10 apples which cost $150,000 and 20 pineapples which cost $288,888.
But the result what I get is: There are 10 apples which cost $150, 000 and 20 pineapples which cost $288, 888.
Can give me a real/workaround solution?
Tried your sample project https://prettyresume.openhtmltopdf.com/, also has same issue: Please note that no space after comma.
try use
.nowrap {
white-space: nowrap;
}
to style your money. such as
<span class="nowrap">$150,000</span>
@vipcxj But my content is dynamic.
surround all your money with span
Line break options are provided by a line break iterator. By default, we use the Java standard library with US locale. We then wrap this in a custom iterator to prevent line breaks at slashes in URLs (this may be removed in a future version). The standard Java line breaker seems to vary by version.
Alternatively, you can plug in your own iterator, with this method on the builder:
/**
* Specify the line breaker. By default a Java default BreakIterator line
* instance is used with US locale. Additionally, this is wrapped with
* UrlAwareLineBreakIterator to also break before the forward slash (/)
* character so that long URIs can be broken on to multiple lines.
*
* You may want to use a BreakIterator with a different locale (wrapped by
* UrlAwareLineBreakIterator or not) or a more advanced BreakIterator from icu4j
* (see the rtl-support module for an example).
*
* @param breaker the text breaker to use
* @return this for method chaining
*/
public final TFinalClass useUnicodeLineBreaker(FSTextBreaker breaker) {
state._lineBreaker = breaker;
return (TFinalClass) this;
}
The sandbox uses the icu4j iterator to enable right-to-left text. You can use this, if needed. You will need to include the rtl-support module.
Something like:
FSTextBreaker beaker = new ICUBreakers.ICULineBreaker(Locale.US);
builder.useUnicodeLineBreaker(breaker);
As @vipcxj suggests, wrapping your critical text in a no-wrap span is still the best solution.
I tried wrapping the critical text in a no-wrap span but the paragraph not pretty justify:
So I tried use icu4j iterator as @danfickle and include the rtl-support module. It's work!
Thank you for your suggestions @vipcxj & @danfickle