Inline PDF comparison draws replacement text on top of the following line
Product: GroupDocs.Comparison for Java
Version: 26.8.2
Platform: Java 21 (Zulu), macOS 15
Summary
In the default inline display mode, when a change makes a line longer than the
original, the overflow is drawn at a fixed 4pt offset from the line it came from,
regardless of the font size or the line pitch of the document. With any normal body
text size the overflow collides with the next line and the two print on top of each
other, making both unreadable.
Steps to reproduce
Attached are two single-page PDFs: five lines of 12pt Times Roman on a 20pt line
pitch, differing in two places (“seven"→"ten”, “five"→"three”). MakePara.java
rebuilds them with PDFBox 3.x.
try (Comparer comparer = new Comparer("para-v1.pdf")) {
comparer.add("para-v2.pdf");
PdfCompareOptions options = new PdfCompareOptions();
options.setDisplayMode(PdfCompareOptions.ComparisonDisplayMode.INLINE);
comparer.compare("inline-result.pdf", options);
}
Expected: the reflowed text makes room for itself, or at least does not overlap.
Actual: see inline-result-page1.png. The wrapped fragment “days.” is drawn
over the top of “Section 5. This agreement is governed by the laws of the state.”
Dumping the baseline of every glyph in the result confirms the spacing:
y=713.20 Section 3. The supplier shall maintain records of every inspection
y=693.20 performed during the reporting period, and shall retain those records
y=673.20 for a minimum of sevten years from the date of the initial inspection.
y=653.20 Section 4. Deviations shall be reported within threefive business
y=640.00 days.
y=633.20 Section 5. This agreement is governed by the laws of the state.
The document’s own line pitch is 20pt throughout. The overflow line “days.” is
placed 13.2pt below its parent line and only 6.8pt above the next one — far
less than the 12pt text needs. We measured the same fixed 4pt offset on other
documents at a 40pt line pitch, where there was ample room, so the offset appears
to be a constant that ignores the space actually available.
CompareOptions.setLeaveGaps(true) (now deprecated) makes no difference: the
output is byte-identical with and without it.
Secondary issue in the same output
Deleted and inserted words are concatenated with no separator — “sevten” for
seven→ten, “threefive” for five→three. Only the colour distinguishes them, so the
result reads as a corrupted word rather than a substitution, and it is lost
entirely in greyscale printing or for a colour-blind reader.
Our current position
We have switched to SIDE_BY_SIDE, which avoids both problems, at the cost of a
page twice as wide and a much larger output file. It would be good to have inline
usable, since it is the mode most reviewers expect.
inline-overprint-repro.zip (30.8 KB)