File size: 7,459 Bytes
fd4d5da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>OCR Result</title>
    <style>

        * {

            margin: 0;

            padding: 0;

            box-sizing: border-box;

        }



        body {

            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;

            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);

            min-height: 100vh;

            display: flex;

            justify-content: center;

            align-items: center;

            padding: 20px;

        }



        .container {

            background: white;

            border-radius: 20px;

            padding: 40px;

            max-width: 800px;

            width: 100%;

            box-shadow: 0 20px 60px rgba(0,0,0,0.3);

        }



        h1 {

            color: #333;

            margin-bottom: 10px;

            font-size: 2em;

            display: flex;

            align-items: center;

            gap: 10px;

        }



        .stats {

            color: #666;

            margin-bottom: 25px;

            font-size: 0.95em;

            display: flex;

            gap: 20px;

            flex-wrap: wrap;

        }



        .stats span {

            background: #f0f2ff;

            padding: 5px 15px;

            border-radius: 20px;

        }



        .result-box {

            background: #f8f9fa;

            border-radius: 12px;

            padding: 25px;

            border: 2px solid #e9ecef;

            min-height: 200px;

            position: relative;

        }



        pre {

            white-space: pre-wrap;

            word-wrap: break-word;

            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;

            font-size: 1em;

            line-height: 1.8;

            color: #333;

            margin: 0;

        }



        .empty-result {

            color: #999;

            font-style: italic;

        }



        .actions {

            margin-top: 25px;

            display: flex;

            gap: 15px;

            flex-wrap: wrap;

        }



        .btn {

            padding: 12px 30px;

            border: none;

            border-radius: 50px;

            font-size: 1em;

            cursor: pointer;

            transition: all 0.3s ease;

            text-decoration: none;

            display: inline-block;

            font-weight: 600;

        }



        .btn-primary {

            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);

            color: white;

        }



        .btn-primary:hover {

            transform: translateY(-2px);

            box-shadow: 0 10px 20px rgba(102, 126, 234, 0.4);

        }



        .btn-secondary {

            background: #e9ecef;

            color: #333;

        }



        .btn-secondary:hover {

            background: #dee2e6;

            transform: translateY(-2px);

        }



        .btn-success {

            background: #28a745;

            color: white;

        }



        .btn-success:hover {

            background: #218838;

            transform: translateY(-2px);

        }



        .toast {

            position: fixed;

            bottom: 20px;

            right: 20px;

            background: #28a745;

            color: white;

            padding: 15px 25px;

            border-radius: 10px;

            box-shadow: 0 4px 15px rgba(0,0,0,0.2);

            transform: translateY(100px);

            opacity: 0;

            transition: all 0.3s ease;

        }



        .toast.show {

            transform: translateY(0);

            opacity: 1;

        }



        @media (max-width: 600px) {

            .container {

                padding: 20px;

            }

            .actions {

                flex-direction: column;

            }

            .btn {

                text-align: center;

            }

        }

    </style>
</head>
<body>
    <div class="container">
        <h1>πŸ“„ Extracted Text</h1>
        <div class="stats">
            <span id="charCount">Characters: 0</span>
            <span id="wordCount">Words: 0</span>
        </div>

        <div class="result-box">
            <pre id="textDisplay">{% if text %}{{ text }}{% else %}<span class="empty-result">No text detected in the image. Please try another image.</span>{% endif %}</pre>
        </div>

        <div class="actions">
            <a href="/" class="btn btn-primary">πŸ“€ Upload Another</a>
            <button class="btn btn-success" onclick="copyText()">πŸ“‹ Copy to Clipboard</button>
            <button class="btn btn-secondary" onclick="downloadText()">πŸ’Ύ Download as TXT</button>
        </div>
    </div>

    <div class="toast" id="toast">βœ… Copied to clipboard!</div>

    <script>

        const textElement = document.getElementById('textDisplay');

        const text = textElement.textContent.trim();



        // Update character and word count

        if (text && text !== 'No text detected in the image. Please try another image.') {

            document.getElementById('charCount').textContent = `Characters: ${text.length}`;

            document.getElementById('wordCount').textContent = `Words: ${text.split(/\s+/).filter(w => w).length}`;

        }



        // Copy to clipboard

        function copyText() {

            const textToCopy = textElement.textContent;

            if (textToCopy && textToCopy !== 'No text detected in the image. Please try another image.') {

                navigator.clipboard.writeText(textToCopy).then(() => {

                    showToast();

                }).catch(() => {

                    // Fallback for older browsers

                    const textarea = document.createElement('textarea');

                    textarea.value = textToCopy;

                    document.body.appendChild(textarea);

                    textarea.select();

                    document.execCommand('copy');

                    document.body.removeChild(textarea);

                    showToast();

                });

            }

        }



        function showToast() {

            const toast = document.getElementById('toast');

            toast.classList.add('show');

            setTimeout(() => {

                toast.classList.remove('show');

            }, 2000);

        }



        // Download as .txt file

        function downloadText() {

            const textToDownload = textElement.textContent;

            if (textToDownload && textToDownload !== 'No text detected in the image. Please try another image.') {

                const blob = new Blob([textToDownload], { type: 'text/plain' });

                const url = URL.createObjectURL(blob);

                const a = document.createElement('a');

                a.href = url;

                a.download = `extracted_text_${Date.now()}.txt`;

                document.body.appendChild(a);

                a.click();

                document.body.removeChild(a);

                URL.revokeObjectURL(url);

            }

        }



        // Keyboard shortcuts

        document.addEventListener('keydown', (e) => {

            if ((e.ctrlKey || e.metaKey) && e.key === 'c') {

                // Let default copy work

            }

        });

    </script>
</body>
</html>