1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 22:58:07 +02:00

Remove terminal white spaces when extracting text from annotation appearances

This commit is contained in:
Calixte Denizet 2024-01-08 18:33:36 +01:00
parent 29faa38dd7
commit 0392feaee4
5 changed files with 46 additions and 3 deletions

View file

@ -1195,7 +1195,7 @@ class Annotation {
firstPosition ||= item.transform.slice(-2);
buffer.push(item.str);
if (item.hasEOL) {
text.push(buffer.join(""));
text.push(buffer.join("").trimEnd());
buffer.length = 0;
}
}
@ -1214,7 +1214,7 @@ class Annotation {
this.reset();
if (buffer.length) {
text.push(buffer.join(""));
text.push(buffer.join("").trimEnd());
}
if (text.length > 1 || text[0]) {
@ -3788,7 +3788,9 @@ class FreeTextAnnotation extends MarkupAnnotation {
this.data.defaultAppearanceData.fontSize ||= 10;
const { fontColor, fontSize } = this.data.defaultAppearanceData;
if (this._contents.str) {
this.data.textContent = this._contents.str.split(/\r\n?|\n/);
this.data.textContent = this._contents.str
.split(/\r\n?|\n/)
.map(line => line.trimEnd());
const { coords, bbox, matrix } = FakeUnicodeFont.getFirstPositionInfo(
this.rectangle,
this.rotation,