diff --git a/VAR.PdfTools/PdfFont.cs b/VAR.PdfTools/PdfFont.cs index 55d641b..3961bd7 100644 --- a/VAR.PdfTools/PdfFont.cs +++ b/VAR.PdfTools/PdfFont.cs @@ -89,13 +89,15 @@ namespace VAR.PdfTools { if (elem is PdfReal widthReal) { - _widths.Add(actualChar, widthReal.Value / glyphSpaceToTextSpace); + double charWidth = widthReal.Value / glyphSpaceToTextSpace; + _widths.Add(actualChar, charWidth); actualChar++; continue; } if (elem is PdfInteger widthInt) { - _widths.Add(actualChar, widthInt.Value / glyphSpaceToTextSpace); + double charWidth = widthInt.Value / glyphSpaceToTextSpace; + _widths.Add(actualChar, charWidth); actualChar++; continue; } diff --git a/VAR.PdfTools/PdfTextExtractor.cs b/VAR.PdfTools/PdfTextExtractor.cs index 895ca00..5b576f5 100644 --- a/VAR.PdfTools/PdfTextExtractor.cs +++ b/VAR.PdfTools/PdfTextExtractor.cs @@ -231,7 +231,7 @@ namespace VAR.PdfTools public PdfTextExtractor(PdfDocumentPage page) { _page = page; - ProcessPage(); + ProcessPageContent(); } #endregion @@ -481,9 +481,14 @@ namespace VAR.PdfTools { foreach (char c in text) { - _textWidth += _font.GetCharWidth(c) * _fontSize; + double charWidth = _font.GetCharWidth(c) * _fontSize; + _textWidth += charWidth; } } + else + { + _textWidth += text.Length * _fontSize * 0.5; + } } private void OpTextPutMultiple(PdfArray array) @@ -497,8 +502,8 @@ namespace VAR.PdfTools } else if(elem is PdfInteger || elem is PdfReal) { - double spacing = PdfElementUtils.GetReal(elem, 0); // FIXME: Apply correctly spacing + //double spacing = PdfElementUtils.GetReal(elem, 0); //_textWidth += spacing; } else if(elem is PdfArray) @@ -512,7 +517,7 @@ namespace VAR.PdfTools #region Private methods - private void ProcessPage() + private void ProcessPageContent() { int unknowCount = 0; for (int i = 0; i < _page.ContentActions.Count; i++)