-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
364 lines (318 loc) · 13 KB
/
app.js
File metadata and controls
364 lines (318 loc) · 13 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
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
let btnmenu = document.getElementById("btnmenu")
let btnmenu1 = document.getElementById("btnmenu1")
let aside = document.getElementById("aside")
btnmenu.addEventListener("click", function () {
btnmenu1.style.display = "block"
btnmenu.style.display = "none"
aside.style.display = "block"
})
btnmenu1.addEventListener("click", function () {
btnmenu.style.display = "block"
btnmenu1.style.display = "none"
aside.style.display = "none"
})
// laptop code
const textArea = document.getElementById("textArea");
const fontSizes = document.getElementById("aside_fontSize");
const fontAligns = document.getElementById("aside_fontalign");
const fontStyles = document.getElementById("aside_fontStyle");
const btnfontUp = document.getElementById("fontUp");
const btnfontDown = document.getElementById("fontDown");
const fonts = document.getElementById("aside_fonts");
const btn_bold = document.getElementById("btnbold");
const btn_italic = document.getElementById("btnitalic");
const btn_underline = document.getElementById("btnunderline");
const format_Change = document.getElementById("formatChange");
const font_color = document.getElementById("Fontcolor");
const back_color = document.getElementById("Backcolor");
const btn_download = document.getElementById("btndownload");
const btn_download1 = document.getElementById("btndownload1");
fontSizes.addEventListener("click", () => {
let fontSize = fontSizes.value;
textArea.value.selected = textArea.style.fontSize = `${fontSize}`;
})
fontAligns.addEventListener("click", () => {
let fontAlign = fontAligns.value;
textArea.value.selected = textArea.style.textAlign = `${fontAlign}`;
})
fontStyles.addEventListener("click", () => {
let fontStyle = fontStyles.value;
textArea.value.selected = textArea.style.textTransform = `${fontStyle}`;
})
let num = 20
btnfontUp.addEventListener("click", () => {
let inc = num++
textArea.value.selected = textArea.style.fontSize = `${inc}px`;
})
btnfontDown.addEventListener("click", () => {
let dic = --num
textArea.value.selected = textArea.style.fontSize = `${dic}px`;
})
fonts.addEventListener("change", () => {
let getfont = fonts.value;
textArea.value.selected = textArea.style.fontFamily = `${getfont}`;
})
btn_bold.addEventListener("click", () => {
let fonts = btn_bold.innerText
if (btn_bold.innerText == "Bold") {
textArea.value.selected = textArea.style.fontWeight = `${fonts}`;
btn_bold.innerText = "Normal";
}
else if (btn_bold.innerText == "Normal") {
textArea.value.selected = textArea.style.fontWeight = `${fonts}`;
btn_bold.innerText = "Bold"
}
})
btn_italic.addEventListener("click", () => {
let fonts = btn_italic.innerText
if (btn_italic.innerText == "Italic") {
textArea.value.selected = textArea.style.fontStyle = `${fonts}`;
btn_italic.innerText = "Normal";
}
else if (btn_italic.innerText == "Normal") {
textArea.value.selected = textArea.style.fontStyle = `${fonts}`;
btn_italic.innerText = "Italic";
}
})
btn_underline.addEventListener("click", () => {
let fonts = btn_underline.innerText
if (btn_underline.innerText == "Underline") {
textArea.value.selected = textArea.style.textDecoration = `${fonts}`;
btn_underline.innerText = "none";
}
else if (btn_underline.innerText == "none") {
textArea.value.selected = textArea.style.textDecoration = `${fonts}`;
btn_underline.innerText = "Underline";
}
})
format_Change.addEventListener("click", () => {
textArea.value.selected = textArea.style.fontSize = `medium`;
textArea.value.selected = textArea.style.textAlign = `left`;
textArea.value.selected = textArea.style.textTransform = `lowercase`;
textArea.value.selected = textArea.style.fontSize = `20px`
textArea.value.selected = textArea.style.fontSize = `20px`
textArea.value.selected = textArea.style.fontFamily = `Times New Roman`
textArea.value.selected = textArea.style.fontWeight = `normal`
textArea.value.selected = textArea.style.fontStyle = `normal`
textArea.value.selected = textArea.style.textDecoration = `none`
btn_bold.innerText = "Bold"
btn_underline.innerText = "Underline"
btn_italic.innerText = "Italic"
textArea.style.color = `black`
textArea.style.backgroundColor = `white`
})
font_color.addEventListener("change", ()=>{
let fontcolor = font_color.value
textArea.value.selected = textArea.style.color = `${fontcolor}`
})
back_color.addEventListener("change", ()=>{
let backcolor = back_color.value
textArea.style.backgroundColor = `${backcolor}`
})
//mobile code
// const textArea = document.getElementById("textArea");
const fontSizes1 = document.getElementById("aside_fontSize1");
const fontAligns1 = document.getElementById("aside_fontalign1");
const fontStyles1 = document.getElementById("aside_fontStyle1");
const btnfontUp1 = document.getElementById("fontUp1");
const btnfontDown1 = document.getElementById("fontDown1");
const fonts1 = document.getElementById("aside_fonts1");
const btn_bold1 = document.getElementById("btnbold1");
const btn_italic1 = document.getElementById("btnitalic1");
const btn_underline1 = document.getElementById("btnunderline1");
const format_Change1 = document.getElementById("formatChange1");
const font_color1 = document.getElementById("Fontcolor1");
const back_color1 = document.getElementById("Backcolor1");
fontSizes1.addEventListener("change", () => {
let fontSize1 = fontSizes1.value;
textArea.value.selected = textArea.style.fontSize = `${fontSize1}`;
})
fontAligns1.addEventListener("change", () => {
let fontAlign1 = fontAligns1.value;
textArea.value.selected = textArea.style.textAlign = `${fontAlign1}`;
})
fontStyles1.addEventListener("change", () => {
let fontStyle1 = fontStyles1.value;
textArea.value.selected = textArea.style.textTransform = `${fontStyle1}`;
})
let numb = 20
btnfontUp1.addEventListener("click", () => {
let inc = numb++
textArea.value.selected = textArea.style.fontSize = `${inc}px`;
})
btnfontDown1.addEventListener("click", () => {
let dic = --numb
textArea.value.selected = textArea.style.fontSize = `${dic}px`;
})
fonts1.addEventListener("change", () => {
let getfont1 = fonts1.value;
textArea.value.selected = textArea.style.fontFamily = `${getfont1}`;
})
btn_bold1.addEventListener("click", () => {
let fonts = btn_bold1.innerText
if (btn_bold1.innerText == "Bold") {
textArea.value.selected = textArea.style.fontWeight = `${fonts}`;
btn_bold1.innerText = "Normal";
}
else if (btn_bold1.innerText == "Normal") {
textArea.value.selected = textArea.style.fontWeight = `${fonts}`;
btn_bold1.innerText = "Bold"
}
})
btn_italic1.addEventListener("click", () => {
let fonts = btn_italic1.innerText
if (btn_italic1.innerText == "Italic") {
textArea.value.selected = textArea.style.fontStyle = `${fonts}`;
btn_italic1.innerText = "Normal";
}
else if (btn_italic1.innerText == "Normal") {
textArea.value.selected = textArea.style.fontStyle = `${fonts}`;
btn_italic1.innerText = "Italic";
}
})
btn_underline1.addEventListener("click", () => {
let fonts = btn_underline1.innerText
if (btn_underline1.innerText == "Underline") {
textArea.value.selected = textArea.style.textDecoration = `${fonts}`;
btn_underline1.innerText = "none";
}
else if (btn_underline1.innerText == "none") {
textArea.value.selected = textArea.style.textDecoration = `${fonts}`;
btn_underline1.innerText = "Underline";
}
})
format_Change1.addEventListener("click", () => {
textArea.value.selected = textArea.style.fontSize = `medium`;
textArea.value.selected = textArea.style.textAlign = `left`;
textArea.value.selected = textArea.style.textTransform = `lowercase`;
textArea.value.selected = textArea.style.fontSize = `20px`
textArea.value.selected = textArea.style.fontSize = `20px`
textArea.value.selected = textArea.style.fontFamily = `Times New Roman`
textArea.value.selected = textArea.style.fontWeight = `normal`
textArea.value.selected = textArea.style.fontStyle = `normal`
textArea.value.selected = textArea.style.textDecoration = `none`
btn_bold.innerText = "Bold"
btn_underline.innerText = "Underline"
btn_italic.innerText = "Italic"
textArea.style.color = `black`
textArea.style.backgroundColor = `white`
})
font_color1.addEventListener("change", ()=>{
let fontcolor = font_color1.value
textArea.value.selected = textArea.style.color = `${fontcolor}`
})
back_color1.addEventListener("change", ()=>{
let backcolor = back_color1.value
textArea.style.backgroundColor = `${backcolor}`
})
// btn_download.addEventListener("click", () => {
// const { jsPDF } = window.jspdf;
// const doc = new jsPDF();
// doc.text(textArea.value, 10, 10);
// doc.save("download.pdf");
// });
btn_download.addEventListener("click", () => {
const { jsPDF } = window.jspdf;
const doc = new jsPDF();
// Get text area styles
const fontSize = parseInt(window.getComputedStyle(textArea).fontSize);
const fontFamily = window.getComputedStyle(textArea).fontFamily;
const fontWeight = window.getComputedStyle(textArea).fontWeight;
const fontStyle = window.getComputedStyle(textArea).fontStyle;
const textAlign = window.getComputedStyle(textArea).textAlign;
const textColor = window.getComputedStyle(textArea).color;
const bgColor = window.getComputedStyle(textArea).backgroundColor;
// Convert color to RGB
const textRGB = textColor.match(/\d+/g);
const bgRGB = bgColor.match(/\d+/g);
// Set background color
doc.setFillColor(parseInt(bgRGB[0]), parseInt(bgRGB[1]), parseInt(bgRGB[2]));
doc.rect(0, 0, 210, 297, "F"); // Full page background
// Set text styles
doc.setFont(fontFamily, fontStyle === "italic" ? "italic" : "normal");
doc.setFontSize(fontSize);
doc.setTextColor(parseInt(textRGB[0]), parseInt(textRGB[1]), parseInt(textRGB[2]));
if (fontWeight === "bold") {
doc.setFont(undefined, "bold");
}
// Split text into multiple lines if needed
const text = textArea.value;
// PDF settings
const marginLeft = 10;
const marginTop = 20;
const maxWidth = 180;
const lineHeight = 10;
const pageHeight = 297; // A4 height in mm
const bottomMargin = 20;
let align = "left";
let textX = marginLeft;
if (textAlign === "center") {
align = "center";
textX = 105; // Center of A4 (210mm width / 2)
} else if (textAlign === "right") {
align = "right";
textX = marginRight;
}
// Split text into multiple lines
let lines = doc.splitTextToSize(text, maxWidth);
let y = marginTop;
// Loop through lines and add pages if needed
lines.forEach((line, index) => {
if (y + lineHeight > pageHeight - bottomMargin) {
doc.addPage();
doc.setFillColor(parseInt(bgRGB[0]), parseInt(bgRGB[1]), parseInt(bgRGB[2]));
doc.rect(0, 0, 210, 297, "F"); // New page background
y = marginTop;
}
doc.text(line, textX, y, { align: align });
y += lineHeight;
});
// Save PDF
doc.save("download.pdf");
});
btn_download1.addEventListener("click", () => {
const { jsPDF } = window.jspdf;
const doc = new jsPDF();
// Get text area styles
const fontSize = parseInt(window.getComputedStyle(textArea).fontSize);
const fontFamily = window.getComputedStyle(textArea).fontFamily;
const fontWeight = window.getComputedStyle(textArea).fontWeight;
const fontStyle = window.getComputedStyle(textArea).fontStyle;
const textAlign = window.getComputedStyle(textArea).textAlign;
const textColor = window.getComputedStyle(textArea).color;
const bgColor = window.getComputedStyle(textArea).backgroundColor;
// Convert color to RGB
const textRGB = textColor.match(/\d+/g);
const bgRGB = bgColor.match(/\d+/g);
// Set background color
doc.setFillColor(parseInt(bgRGB[0]), parseInt(bgRGB[1]), parseInt(bgRGB[2]));
doc.rect(0, 0, 210, 297, "F"); // Full page background
// Set text styles
doc.setFont(fontFamily, fontStyle === "italic" ? "italic" : "normal");
doc.setFontSize(fontSize);
doc.setTextColor(parseInt(textRGB[0]), parseInt(textRGB[1]), parseInt(textRGB[2]));
if (fontWeight === "bold") {
doc.setFont(undefined, "bold");
}
// Split text into multiple lines if needed
const text = textArea.value;
const marginLeft = 10;
const marginTop = 20;
const maxWidth = 180;
const lineHeight = 10;
let align = "left";
let textX = marginLeft;
if (textAlign === "center") {
align = "center";
textX = 105; // Center of A4 (210mm width / 2)
} else if (textAlign === "right") {
align = "right";
textX = marginRight;
}
// Split text into multiple lines
const lines = doc.splitTextToSize(text, maxWidth);
// Draw text with alignment
doc.text(lines, textX, marginTop + lineHeight, { align: align });
// Save PDF
doc.save("download.pdf");
});