Use Rect class for size definition of TextElements and pages.
This commit is contained in:
25
VAR.PdfTools/Maths/Rect.cs
Normal file
25
VAR.PdfTools/Maths/Rect.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VAR.PdfTools.Maths
|
||||
{
|
||||
public class Rect
|
||||
{
|
||||
public double XMin { get; set; }
|
||||
public double XMax { get; set; }
|
||||
public double YMin { get; set; }
|
||||
public double YMax { get; set; }
|
||||
|
||||
public void Add(Rect rect)
|
||||
{
|
||||
if (rect.XMax > XMax) { XMax = rect.XMax; }
|
||||
if (rect.YMax > YMax) { YMax = rect.YMax; }
|
||||
if (rect.XMin < XMin) { XMin = rect.XMin; }
|
||||
if (rect.YMin < YMin) { YMin = rect.YMin; }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -87,6 +87,19 @@ namespace VAR.PdfTools
|
||||
return Characters.Average(c => c.Width);
|
||||
}
|
||||
|
||||
public Rect GetRect()
|
||||
{
|
||||
double x = GetX();
|
||||
double y = GetY();
|
||||
return new Rect
|
||||
{
|
||||
XMin = x,
|
||||
YMax = y,
|
||||
XMax = x + VisibleWidth,
|
||||
YMin = y - VisibleHeight,
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
|
||||
@@ -652,6 +652,18 @@ namespace VAR.PdfTools
|
||||
|
||||
#region Public methods
|
||||
|
||||
public Rect GetRect()
|
||||
{
|
||||
Rect rect = null;
|
||||
foreach (PdfTextElement textElement in _textElements)
|
||||
{
|
||||
Rect elementRect = textElement.GetRect();
|
||||
if (rect == null) { rect = elementRect; }
|
||||
rect.Add(elementRect);
|
||||
}
|
||||
return rect;
|
||||
}
|
||||
|
||||
public List<string> GetColumnAsStrings(string column, bool fuzzy =true)
|
||||
{
|
||||
PdfTextElement columnHead = FindElementByText(column, fuzzy);
|
||||
|
||||
@@ -63,6 +63,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Maths\Matrix3x3.cs" />
|
||||
<Compile Include="Maths\Rect.cs" />
|
||||
<Compile Include="PdfContentAction.cs" />
|
||||
<Compile Include="PdfDocument.cs" />
|
||||
<Compile Include="PdfDocumentPage.cs" />
|
||||
|
||||
Reference in New Issue
Block a user