-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.html
More file actions
executable file
·457 lines (390 loc) · 17.2 KB
/
Copy pathindex.html
File metadata and controls
executable file
·457 lines (390 loc) · 17.2 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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Img2Pdf - Convert PNG/JPG/JPEG to PDF in your browser!</title>
<meta name="description"
content="Free, In-browser, Privacy friendly image to PDF convertor. Supports JPG/JPEG,PNG Image file formats and multiple image conversion at once. Your content stays secure in your browser itself.">
<link rel="shortcut icon" type="image/x-icon" href="img2pdf-favicon.ico">
<link rel="icon" type="image/x-icon" href="img2pdf-favicon.ico">
<link rel="stylesheet" href="css/animate.min-4.1.0.css">
<link rel="stylesheet" href="css/bulma.min-0.9.0.css">
<script defer src="js/pdfkit-standalone-0.10.0.js"></script>
<script defer src="js/blob-stream-0.1.3.js"></script>
<script defer src="js/compressor-min-1.0.6.js"></script>
<script async src="js/fa-5.3.1.js"></script>
<link href="css/filepond.min-4.19.2.css" rel="stylesheet">
<link href="css/filepond-plugin-image-overlay.min-1.0.6.css" rel="stylesheet">
<link href="css/filepond-plugin-image-preview.min-4.6.4.css" rel="stylesheet">
</head>
<body>
<style>
.iframe-container {
overflow: hidden;
height: 100%;
width: 100%;
position: relative;
}
.iframe-container iframe {
border: 0;
height: 100%;
left: 0;
position: absolute;
top: 0;
width: 100%;
}
@media screen and (max-width: 780px) {
.iframe-container {
padding-top: 125%;
}
}
.tile::-webkit-scrollbar {
width: 0 !important
}
.tile {
scrollbar-width: none;
}
html::-webkit-scrollbar {
width: 0 !important
}
html {
scrollbar-width: none;
}
.logo-block {
display: inline-block;
}
/* .filepond--root {
max-height: 40em;
} */
.filepond--item {
width: calc(50% - .5em);
}
.tile-container {
width: 100%;
margin: 9px;
}
.params-div {
display: flex;
align-items: center;
justify-content: center;
flex-direction: row;
width: 100%;
}
.cq-range-div {
flex: 1 1 content;
}
#generate-pdf {
flex: 1 1 content;
}
.range-input {
vertical-align: middle;
}
#generate-pdf:hover {
transform: translateY(-2px);
}
.pattern {
background-color: #363636;
background-image: url("data:image/svg+xml,%3Csvg width='6' height='6' viewBox='0 0 6 6' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23ffffff' fill-opacity='0.21' fill-rule='evenodd'%3E%3Cpath d='M5 0h1L0 6V5zM6 5v1H5z'/%3E%3C/g%3E%3C/svg%3E");
}
</style>
<script src="js/filepond-plugin-image-preview.min-4.6.4.js"></script>
<script src="js/filepond-plugin-image-overlay.min-1.0.6.js"></script>
<script src="js/filepond-plugin-image-crop.min-2.0.4.js"></script>
<script src="js/filepond-plugin-file-validate-type.min-1.2.5.js"></script>
<!-- <script src="js/filepond-plugin-file-encode.min-2.1.6.js"></script> -->
<script src="js/filepond.min-4.19.2.js"></script>
<script>
FilePond.registerPlugin(
// FilePondPluginFileEncode,
FilePondPluginImageCrop,
FilePondPluginImagePreview,
FilePondPluginImageOverlay,
FilePondPluginFileValidateType
);
</script>
<section class="hero is-fullheight is-bold pattern">
<div class="hero-body">
<div class="tile-container">
<div class="tile is-ancestor">
<div class="tile is-5 is-vertical is-parent" style="max-height: 90vh;overflow: scroll;">
<div class="tile is-child box animate__animated animate__zoomInDown animate__delay-1s">
<div class="content">
<h1 class="has-text-grey-darker has-text-weight-semibold">Img2Pdf</h1>
<h6 class="has-text-grey-dark">Made with ❤️ towards Privacy ⭐</h6>
</div>
<div id="logo" style="text-align: center; margin-bottom: 10px;">
<div class="buttons logo-block" style="margin: 0 10px;">
<span class="icon is-large has-text-info">
<i class="fas fa-images fa-3x"></i>
</span>
</div>
<div class="buttons logo-block" style="margin: 0 0 0 5px;">
<span class="icon is-medium has-text-success">
<i class="fas fa-angle-double-right fa-3x"></i>
</span>
</div>
<div class="buttons logo-block" style="margin: 0 10px;">
<span class="icon is-large has-text-danger">
<i class="fas fa-file-pdf fa-3x"></i>
</span>
</div>
</div>
</div>
<div class="tile is-child box animate__animated animate__zoomInDown animate__delay-1s">
<div class="params-div">
<div class="cq-range-div">
<label for="compress-quality">Image Compression: </label>
<input class="range-input" id="compress-quality" type="range" min="0" max="1"
value="0.5" step="0.1">
<output style="font-size: small;" id="output-compress-quality"
for="compress-quality">0.5</output>
</div>
<button id="generate-pdf" class="button is-danger is-rounded is-light"
style="margin-left: 20px;"> <span class="icon">
<i class="fas fa-file-pdf"></i>
</span>
<span>Generate PDF</span></button>
</div>
<br>
<div class="content">
<input type="file" id="input_img" name="input_img" multiple>
</div>
<br>
<div class="tags is-centered">
<span class="tag is-rounded is-warning">Privacy Focused</i></span>
<span class="tag is-rounded is-info">No Tracking</span>
<span class="tag is-rounded is-danger">No Ads </span>
<span class="tag is-rounded is-success">Fast Conversion</span>
<span class="tag is-rounded is-link">Secure</span>
<span class="tag is-rounded is-primary is-light">Input Reordering</span>
<span class="tag is-rounded is-dark">Built-In Compression</span>
<span class="tag is-rounded is-danger is-light">Drag n Drop</span>
</div>
<div class="buttons is-centered">
<a class="button" href="https://github.com/OpenToolKit/Img2Pdf">
<span class="icon">
<i class="fab fa-github"></i>
</span>
<span>GitHub</span>
</a>
</div>
<div class="buttons is-centered">
<a href="https://bulma.io" target="_blank">
<img src="res/made-with-bulma--semiblack.png" alt="Made with Bulma" width="153"
height="33">
</a>
</div>
</div>
</div>
<div class="tile is-7 is-parent">
<div class="tile is-child box animate__animated animate__zoomInDown animate__delay-1s">
<div class="iframe-container">
<iframe frameborder="0" scrolling="no" id="output_pdf" src="res/Preview.pdf"></iframe>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<script>
var currentFileList = [];
var refreshingInput;
function updateCurrentFileList(files) {
window.currentFileList = files;
// currentFileList.forEach(file => { console.log(file.filename) });
// notifyInputRefresh();
}
var generate_pdf = document.getElementById("generate-pdf");
generate_pdf.addEventListener("click", notifyInputRefresh);
function notifyInputRefresh() {
if (refreshingInput) {
window.clearTimeout(refreshingInput);
}
refreshingInput = window.setTimeout(() => {
toggleButtonLoading();
onInputImage();
}, 10);
}
const inputElement = document.getElementById("input_img");
const pond = FilePond.create(inputElement, {
labelIdle: `Drag & Drop your picture or <span class="filepond--label-action">Browse</span>`,
allowReorder: true,
imageCropAspectRatio: '3:1',
// imagePreviewMaxHeight: 200,
imagePreviewHeight: 75,
allowFileTypeValidation: true,
acceptedFileTypes: ['image/png', 'image/jpeg'],
// allowFileEncode: false,
onaddfile: (err, fileItem) => {
disablePreviewClick();
},
onupdatefiles: (files) => {
updateCurrentFileList(files);
},
onreorderfiles: (files, origin, target) => {
updateCurrentFileList(files);
}
});
function disablePreviewClick() {
window.setTimeout(() => {
var imagePreviews = document.querySelectorAll('.filepond--image-preview');
imagePreviews.forEach(imagePreview => {
imagePreview.classList.remove('clickable');
imagePreview.removeEventListener('click', () => { });
});
}, 1000);
};
var CQ = -1;
const compress_quality = document.getElementById('compress-quality');
compress_quality.addEventListener('input', setCompressQuality);
function onInputImage() {
var input_files = [...window.currentFileList];
var input_file_count = input_files.length;
var input_img_data = new Array(input_file_count).fill(-1);
// console.log("images: " + input_file_count);
const output_pdf = document.getElementById('output_pdf')
// console.log(output_pdf.src);
if (input_files.length == 0) {
if (!output_pdf.src.endsWith("res/Preview.pdf")) {
output_pdf.src = "res/Preview.pdf";
}
toggleButtonLoading();
}
input_files.forEach((fp_file, i) => {
const file = fp_file.file;
if (!file.type.startsWith('image/')) {
if (!output_pdf.src.endsWith("res/Preview.pdf")) {
output_pdf.src = "res/Preview.pdf";
}
toggleButtonLoading();
return;
}
const reader = new FileReader();
reader.onload = async function (e) {
const img = await getImgObj(e.target.result, file.name);
input_img_data[i] = img;
var filled = input_img_data.reduce((count, value) => {
return count + (value != -1);
}, 0);
if (filled == input_file_count) {
generatePdf(input_img_data);
toggleButtonLoading();
}
}
if (CQ != -1) {
async function waitTillCompress(file) {
var compress_out = await compressImg(file);
reader.readAsDataURL(compress_out)
}
waitTillCompress(file);
} else {
reader.readAsDataURL(file);
}
});
}
function setCompressQuality() {
var cq_input = Number(this.value);
if (cq_input == 0) {
CQ = -1;
} else {
CQ = 1 - cq_input;
}
document.getElementById("output-compress-quality").value = cq_input;
// notifyInputRefresh()
}
function toggleButtonLoading() {
var generate_pdf = document.getElementById("generate-pdf");
if (generate_pdf.classList.contains("is-loading")) {
generate_pdf.classList.remove("is-loading");
} else {
generate_pdf.classList.add("is-loading");
}
if (generate_pdf.classList.contains("animate__infinite")) {
generate_pdf.classList.remove("animate__animated");
generate_pdf.classList.remove("animate__pulse");
generate_pdf.classList.remove("animate__infinite");
} else {
generate_pdf.classList.add("animate__animated");
generate_pdf.classList.add("animate__pulse");
generate_pdf.classList.add("animate__infinite");
}
}
function compressImg(file) {
return new Promise(function (resolve, reject) {
var opt = {
strict: true,
checkOrientation: true,
maxWidth: Infinity,
maxHeight: Infinity,
minWidth: 0,
minHeight: 0,
width: undefined,
height: undefined,
/**
* The quality of the output image.
* It must be a number between `0` and `1`,
* and only available for `image/jpeg` and `image/webp` images.
* Check out {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob canvas.toBlob}.
* @type {number}
*/
quality: (CQ != -1) ? CQ : 0.8,
mimeType: 'auto',
/**
* PNG files over this value (5 MB by default) will be converted to JPEGs.
* To disable this, just set the value to `Infinity`.
* @type {number}
*/
convertSize: 1,
beforeDraw: null,
drew: null,
success(result) {
resolve(result)
},
error(err) {
console.log(err.message);
},
};
new Compressor(file, opt);
});
}
function getImgObj(ibase64, name) {
return new Promise(function (resolve, reject) {
var img = new Image();
img.onload = function () {
resolve(img);
}
img.src = ibase64;
img.name = name;
});
}
function generatePdf(img_data) {
var options = {
autoFirstPage: false,
compress: false
};
const doc = new PDFDocument(options);
doc.info = {
Title: 'ImageDoc.pdf',
Author: 'Img2Pdf',
Keywords: 'https://opentoolkit.github.io/Img2Pdf/'
}
const stream = doc.pipe(blobStream());
for (let i = 0; i < img_data.length; i++) {
doc.addPage({
size: [img_data[i].width, img_data[i].height]
})
doc.image(img_data[i].src, 0, 0);
}
doc.end();
stream.on('finish', function () {
var output_pdf = document.getElementById('output_pdf')
var output_blob = stream.toBlob('application/pdf');
output_pdf.src = stream.toBlobURL('application/pdf');
})
}
</script>
</body>
</html>