openhtmltopdf icon indicating copy to clipboard operation
openhtmltopdf copied to clipboard

Prevent line break after comma / dot / special characters

Open lingling7250 opened this issue 3 years ago • 6 comments

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?

lingling7250 avatar Sep 08 '21 05:09 lingling7250

Tried your sample project https://prettyresume.openhtmltopdf.com/, also has same issue: Please note that no space after comma. image

lingling7250 avatar Sep 09 '21 04:09 lingling7250

try use

            .nowrap {
                white-space: nowrap;
            }

to style your money. such as

<span class="nowrap">$150,000</span>

vipcxj avatar Sep 09 '21 06:09 vipcxj

@vipcxj But my content is dynamic.

lingling7250 avatar Sep 09 '21 06:09 lingling7250

surround all your money with span

vipcxj avatar Sep 09 '21 06:09 vipcxj

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.

danfickle avatar Sep 10 '21 08:09 danfickle

I tried wrapping the critical text in a no-wrap span but the paragraph not pretty justify: image

So I tried use icu4j iterator as @danfickle and include the rtl-support module. It's work!

Thank you for your suggestions @vipcxj & @danfickle

lingling7250 avatar Sep 17 '21 08:09 lingling7250