diff --git a/src/pdf/Extract.js b/src/pdf/Extract.js index bc1f061..6846326 100644 --- a/src/pdf/Extract.js +++ b/src/pdf/Extract.js @@ -34,8 +34,7 @@ class ExtractText { x += line.font.direction * line.wordSpacing; continue; } else if (util.isNum(glyph)) { - const spaceSize = -glyph * line.font.size * 0.001; - x += spaceSize; + x += -glyph * line.font.size * 0.001; if (!line.font.spaceWidthIsSet && line.isSpace(glyph)) { partial += " "; } @@ -65,10 +64,10 @@ class ExtractText { line.x = page.x; line.y = page.y; line.setText(partial); - const isNew = lineList.y !== 0 && Math.abs(line.y - lineList.y) > line.font.size + const isNew = lineList.y !== 0 && Math.abs(line.y - lineList.y) > line.font.size; if(isNew) { - lineList.printText() - lineList = page.currentObject.newLine() + lineList.printText(); + lineList = page.currentObject.newLine(); } lineList.x = startX; lineList.y = startY; @@ -85,7 +84,7 @@ class ExtractText { getFontFamily(name, dependencies) { for(let i = 0;i { const txtLineOut = this.formatTextLine(textLine); txtObjOut.lines.push(txtLineOut); @@ -41,9 +46,7 @@ class FormatterJSON { text: [], x: textLine.x, y: textLine.y, - w: textLine.w, - h: textLine.h, - textMatrix: textLine.textMatrix, + width: textLine.width, } textLine.getData().forEach(textFont => { const txtFontOut = this.formatTextFont(textFont); @@ -65,6 +68,7 @@ class FormatterJSON { family: textFont.font.family, style: textFont.font.style, weight: textFont.font.weight, + vertical: textFont.font.vertical, }, text: textFont.getText(), charSpacing: textFont.charSpacing, diff --git a/src/pdf/model/text/TextLine.js b/src/pdf/model/text/TextLine.js index 1ccd67f..8d60ef5 100644 --- a/src/pdf/model/text/TextLine.js +++ b/src/pdf/model/text/TextLine.js @@ -10,9 +10,7 @@ class TextLine extends PdfObject { super(); this._textFonts = []; this.width = 0; - this.height = 0; } - /** * Adds line with font to text * @param {TextFont} line @@ -45,6 +43,9 @@ class TextLine extends PdfObject { * @returns {Array} of {@link TextFont} */ getData() { + // this._textFonts.sort((a, b) => a.x >= b.x); + this.x = this._textFonts[0].x; + this.width = this._textFonts[this._textFonts.length - 1].x - this.x; return this._textFonts; } }