forked from SergiyStoyan/PdfDocumentParser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnchorPdfTextControl.cs
74 lines (65 loc) · 3.06 KB
/
AnchorPdfTextControl.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//********************************************************************************************
//Author: Sergiy Stoyan
// s.y.stoyan@gmail.com, sergiy.stoyan@outlook.com, stoyan@cliversoft.com
// http://www.cliversoft.com
//********************************************************************************************
using System;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Cliver.PdfDocumentParser
{
public partial class AnchorPdfTextControl : AnchorControl
{
public AnchorPdfTextControl(TextAutoInsertSpace textAutoInsertSpace)
{
InitializeComponent();
this.textAutoInsertSpace = textAutoInsertSpace;
cSearchRectangleMargin.CheckedChanged += delegate
{
SearchRectangleMargin.Enabled = cSearchRectangleMargin.Checked;
if (SearchRectangleMargin.Value >= 0)
return;
SearchRectangleMargin.Value = cSearchRectangleMargin.Checked ? ((anchor == null || anchor.ParentAnchorId != null) ? (decimal)Settings.Constants.CoordinateDeviationMargin : 100) : -1;
};
}
TextAutoInsertSpace textAutoInsertSpace;
override protected object getObject()
{
if (anchor == null)
anchor = new Template.Anchor.PdfText();
anchor.PositionDeviationIsAbsolute = PositionDeviationIsAbsolute.Checked;
anchor.PositionDeviation = (float)PositionDeviation.Value;
anchor.SearchRectangleMargin = SearchRectangleMargin.Enabled ? (int)SearchRectangleMargin.Value : -1;
anchor.IgnoreOtherCharsInRectangle = IgnoreOtherCharsInRectangle.Checked;
anchor.IgnoreInvisibleChars = IgnoreInvisibleChars.Checked;
return anchor;
}
protected override void initialize(DataGridViewRow row)
{
anchor = (Template.Anchor.PdfText)row.Tag;
if (anchor == null)
anchor = new Template.Anchor.PdfText();
StringBuilder sb = new StringBuilder();
foreach (var l in Page.GetLines(anchor.CharBoxs.Select(x => new Pdf.CharBox { Char = x.Char, R = x.Rectangle.GetSystemRectangleF() }), textAutoInsertSpace, null))
{
foreach (var cb in l.CharBoxs)
sb.Append(cb.Char);
sb.Append("\r\n");
}
text.Text = sb.ToString();
PositionDeviationIsAbsolute.Checked = anchor.PositionDeviationIsAbsolute;
try
{
PositionDeviation.Value = (decimal)anchor.PositionDeviation;
}
catch { }
SearchRectangleMargin.Value = anchor.SearchRectangleMargin;
SearchRectangleMargin.Enabled = cSearchRectangleMargin.Checked;
cSearchRectangleMargin.Checked = SearchRectangleMargin.Value >= 0;
IgnoreOtherCharsInRectangle.Checked = anchor.IgnoreOtherCharsInRectangle;
IgnoreInvisibleChars.Checked = anchor.IgnoreInvisibleChars;
}
Template.Anchor.PdfText anchor;
}
}