forked from SergiyStoyan/PdfDocumentParser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFieldPdfTextControl.cs
79 lines (69 loc) · 3.15 KB
/
FieldPdfTextControl.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
75
76
77
78
79
//********************************************************************************************
//Author: Sergiy Stoyan
// s.y.stoyan@gmail.com, sergiy.stoyan@outlook.com, stoyan@cliversoft.com
// http://www.cliversoft.com
//********************************************************************************************
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Text.RegularExpressions;
namespace Cliver.PdfDocumentParser
{
public partial class FieldPdfTextControl : FieldControl
{
public FieldPdfTextControl()
{
InitializeComponent();
SpecialTextAutoInsertSpace.CheckedChanged += delegate { synchronizeControls(); };
synchronizeControls();
}
void synchronizeControls()
{
gSpacing.Visible = SpecialTextAutoInsertSpace.Checked;
}
override protected object getObject()
{
if (field == null)
field = new Template.Field.PdfText();
field.ColumnOfTable = (string)ColumnOfTable.SelectedItem;
if (SpecialTextAutoInsertSpace.Checked)
field.TextAutoInsertSpace = new TextAutoInsertSpace { Threshold = (float)textAutoInsertSpace_Threshold.Value, Representative = Regex.Unescape(textAutoInsertSpaceRepresentative.Text), IgnoreSourceSpaces = textAutoInsertSpaceIgnoreSourceSpaces.Checked };
else
field.TextAutoInsertSpace = null;
return field;
}
protected override void initialize(DataGridViewRow row, object value)
{
field = (Template.Field.PdfText)row.Tag;
if (field == null)
field = new Template.Field.PdfText();
List<string> fieldNames = template.Fields.Where(a => a.ColumnOfTable == null).Select(a => a.Name).Distinct().ToList();
fieldNames.Remove(field.Name);
fieldNames.Insert(0, "");
ColumnOfTable.DataSource = fieldNames;
ColumnOfTable.SelectedItem = field.ColumnOfTable;
SpecialTextAutoInsertSpace.Checked = field.TextAutoInsertSpace != null;
if (field.TextAutoInsertSpace != null)
{
textAutoInsertSpace_Threshold.Value = (decimal)field.TextAutoInsertSpace.Threshold;
textAutoInsertSpaceRepresentative.Text = Regex.Escape(field.TextAutoInsertSpace.Representative);
textAutoInsertSpaceIgnoreSourceSpaces.Checked = field.TextAutoInsertSpace.IgnoreSourceSpaces;
}
else
{
textAutoInsertSpace_Threshold.Value = (decimal)template.TextAutoInsertSpace.Threshold;
textAutoInsertSpaceRepresentative.Text = template.TextAutoInsertSpace.Representative;
textAutoInsertSpaceIgnoreSourceSpaces.Checked = template.TextAutoInsertSpace.IgnoreSourceSpaces;
}
if (value != null)
Value.Text = Page.NormalizeText((string)value);
}
Template.Field.PdfText field;
}
}