danfickle/openhtmltopdf

Justify bug solution backport from flying saucer

halcsi opened this issue · 1 comments

https://stackoverflow.com/questions/36982586/flying-saucer-generates-pdf-with-badly-justified-text/37118310#37118310

The problem seems to be that flying-soucer does not use the Paragraph of the underlying itext, but splits the text into the individual lines itself. While doing it, flying-soucer does not remove the trailing empty spaces.

A quick fix is to insert currentLine.trimTrailingSpace(c); before this call to save().

You should take 3 line in the
openhtmltopdf-core\src\main\java\com\openhtmltopdf\layout\InlineBoxing.java

			if (lbContext.isNeedsNewLine()) {
+				if (iB.getStyle().isTextJustify()) {
+             		      		currentLine.trimTrailingSpace(c);
+             		        }
                        saveLine(currentLine, c, box, minimumLineHeight,
                                maxAvailableWidth, pendingFloats,
                                hasFirstLinePEs, pendingInlineLayers, markerData,
                                contentStart, isAlwaysBreak(c, box, breakAtLine, lineOffset));

I tested and works correctly.

Thank you the fast finish!