From 34e742427302b35d821d61483784554cd6d48c45 Mon Sep 17 00:00:00 2001 From: "Valeriano A.R" Date: Wed, 11 Oct 2017 16:47:10 +0200 Subject: [PATCH] PdfCharElement: Width attribute --- VAR.PdfTools.Workbench/FrmPdfInfo.cs | 9 ++++++--- VAR.PdfTools/PdfTextExtractor.cs | 5 ++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/VAR.PdfTools.Workbench/FrmPdfInfo.cs b/VAR.PdfTools.Workbench/FrmPdfInfo.cs index f0a153d..d46a573 100644 --- a/VAR.PdfTools.Workbench/FrmPdfInfo.cs +++ b/VAR.PdfTools.Workbench/FrmPdfInfo.cs @@ -250,9 +250,8 @@ namespace VAR.PdfTools.Workbench (int)(textElementPageY * Scale), (int)(textElementWidth * Scale), (int)(textElementHeight * Scale), - Scale); - - + 5); + using (Font font = new Font("Arial", (int)(textElementHeight * Scale), GraphicsUnit.Pixel)) { foreach (PdfCharElement c in textElement.Characters) @@ -266,6 +265,10 @@ namespace VAR.PdfTools.Workbench (int)((textElementPageX + c.Displacement) * Scale), (int)(textElementPageY * Scale), 2, 2); + gc.FillRectangle(Brushes.Green, + (int)((textElementPageX + c.Displacement + c.Width) * Scale), + (int)(textElementPageY * Scale), + 2, 2); } } } diff --git a/VAR.PdfTools/PdfTextExtractor.cs b/VAR.PdfTools/PdfTextExtractor.cs index 2dd07c1..2af02e4 100644 --- a/VAR.PdfTools/PdfTextExtractor.cs +++ b/VAR.PdfTools/PdfTextExtractor.cs @@ -11,6 +11,7 @@ namespace VAR.PdfTools { public string Char; public double Displacement; + public double Width; } public class PdfTextElement @@ -135,6 +136,7 @@ namespace VAR.PdfTools { Char = c.Char, Displacement = (c.Displacement * textElem.Matrix.Matrix[0, 0]), + Width = (c.Width * textElem.Matrix.Matrix[0, 0]), }); } textElem.Childs = new List(); @@ -321,8 +323,8 @@ namespace VAR.PdfTools { string realChar = _font.ToUnicode(c); if (realChar == "\0") { continue; } - _listCharacters.Add(new PdfCharElement { Char = _font.ToUnicode(c), Displacement = _textWidth, }); double charWidth = _font.GetCharWidth(c) * _fontSize; + _listCharacters.Add(new PdfCharElement { Char = _font.ToUnicode(c), Displacement = _textWidth, Width = charWidth }); _textWidth += charWidth; _textWidth += ((c == 0x20) ? _wordSpacing : _charSpacing); } @@ -620,6 +622,7 @@ namespace VAR.PdfTools { Char = c.Char, Displacement = (c.Displacement + neighbourXMin) - blockXMin, + Width = c.Width, }); } }