-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileConverter.cs
More file actions
165 lines (132 loc) · 5.09 KB
/
Copy pathFileConverter.cs
File metadata and controls
165 lines (132 loc) · 5.09 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using PdfiumViewer;
namespace WindowsFormsApp7
{
public partial class FileConverter : Form
{
private string folderPath;
private List<(string FileName, string PageNumber, string ExtractedText)> extractedData = new List<(string FileName, string PageNumber, string ExtractedText)>();
public FileConverter(string selectedFolder)
{
InitializeComponent();
folderPath = selectedFolder;
}
private void FileConverter_Load(object sender, EventArgs e)
{
if (!backgroundWorker1.IsBusy)
{
backgroundWorker1.RunWorkerAsync();
}
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
string[] pdfFiles = Directory.GetFiles(folderPath, "*.pdf");
int totalSteps = pdfFiles.Length;
int currentStep = 0;
foreach (var pdfPath in pdfFiles)
{
if (backgroundWorker1.CancellationPending)
{
e.Cancel = true;
return;
}
try
{
List<(string FileName, string PageNumber, string ExtractedText)> pageResults =
PdfProcessor.ProcessPdfForOcr(pdfPath, backgroundWorker1);
extractedData.AddRange(pageResults);
}
catch (Exception ex)
{
Console.WriteLine($"Error processing PDF file '{pdfPath}': {ex.Message}");
extractedData.Add((Path.GetFileName(pdfPath), "N/A", $"Error: {ex.Message}"));
}
currentStep++;
int progress = (int)((currentStep / (float)totalSteps) * 100);
backgroundWorker1.ReportProgress(progress);
}
}
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (e.Cancelled)
{
MessageBox.Show("The operation has been canceled.", "Operation Canceled", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else if (e.Error != null)
{
MessageBox.Show($"An unhandled error occurred: {e.Error.Message}\n{e.Error.StackTrace}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
frmExtract exportForm = new frmExtract(extractedData, null);
exportForm.Show();
this.Hide();
}
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
guna2ProgressBar1.Value = e.ProgressPercentage;
lblPercentage.Text = $" Complete: {e.ProgressPercentage}%";
}
private void btnHome_Click(object sender, EventArgs e)
{
Form1 form = new Form1();
form.Show();
this.Hide();
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
ControlPaint.DrawBorder(e.Graphics, panel1.ClientRectangle,
Color.Black, 0, ButtonBorderStyle.None,
Color.Black, 0, ButtonBorderStyle.None,
Color.Black, 0, ButtonBorderStyle.None,
Color.Black, 1, ButtonBorderStyle.Dashed);
}
private void guna2btnClose_Click(object sender, EventArgs e)
{
if (backgroundWorker1.IsBusy)
{
backgroundWorker1.CancelAsync();
}
else
{
Form1 form = new Form1();
form.Show();
this.Hide();
}
}
private void button3_Click(object sender, EventArgs e)
{
Form1 fr = new Form1();
fr.Show();
this.Hide();
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("📧 Email: ame2er15@gmail.com\n☎️ Phone: +966-501744482\n",
"Technical support", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void panel2_Paint(object sender, PaintEventArgs e)
{
ControlPaint.DrawBorder(e.Graphics, panel2.ClientRectangle,
Color.Black, 0, ButtonBorderStyle.None,
Color.Black, 0, ButtonBorderStyle.None,
Color.Black, 0, ButtonBorderStyle.None,
Color.Black, 1, ButtonBorderStyle.Dashed);
}
private void FileConverter_FormClosed(object sender, FormClosedEventArgs e)
{
Application.Exit();
}
}
}