diff --git a/index.js b/index.js index c8943a8..f808ea0 100644 --- a/index.js +++ b/index.js @@ -1,33 +1,35 @@ -const express = require('express') -const bodyParser = require('body-parser') -const mergeRouter = require('./routes/merge'); -const splitRouter = require('./routes/split'); -const editorRouter = require('./routes/editor'); -const watermarkRouter = require('./routes/watermark'); -const deleteRouter = require('./routes/delete'); -const pageNoRoute = require('./routes/pageno'); -const rotatePdf = require('./routes/rotate'); -const pdfToWord = require('./routes/pdf-to-word') -const pdfToExcel = require('./routes/pdftoexcel') -const pdfToPpt = require('./routes/pdf-to-ppt') -const pdfToPng = require('./routes/pdf-to-png') -const pdfToJpg = require('./routes/pdf-to-jpg') -const pdfToJson = require('./routes/pdf-to-json'); -const pdfToTiff = require('./routes/pdf-to-tiff') -const pdfToTxt = require('./routes/pdf-to-txt') -const wordToPdf = require('./routes/word-to-pdf') -const cors = require('cors'); +const express = require("express"); +const bodyParser = require("body-parser"); +const mergeRouter = require("./routes/merge"); +const splitRouter = require("./routes/split"); +const editorRouter = require("./routes/editor"); +const watermarkRouter = require("./routes/watermark"); +const deleteRouter = require("./routes/delete"); +const pageNoRoute = require("./routes/pageno"); +const rotatePdf = require("./routes/rotate"); +const pdfToWord = require("./routes/pdf-to-word"); +const pdfToExcel = require("./routes/pdftoexcel"); +const pdfToPpt = require("./routes/pdf-to-ppt"); +const pdfToPng = require("./routes/pdf-to-png"); +const pdfToJpg = require("./routes/pdf-to-jpg"); +const pdfToJson = require("./routes/pdf-to-json"); +const pdfToTiff = require("./routes/pdf-to-tiff"); +const pdfToTxt = require("./routes/pdf-to-txt"); +const wordToPdf = require("./routes/word-to-pdf"); +const compressPdf = require("./routes/compress"); +const esign = require("./routes/esign"); +const cors = require("cors"); const app = express(); -const path = require('path'); +const path = require("path"); app.use(cors()); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true })); app.use(express.urlencoded({ extended: true })); -app.set('views', path.join(__dirname, '/views')) -app.set('view engine', 'ejs') -app.use(express.static(path.join(__dirname, 'public'))); +app.set("views", path.join(__dirname, "/views")); +app.set("view engine", "ejs"); +app.use(express.static(path.join(__dirname, "public"))); app.use(mergeRouter); app.use(splitRouter); app.use(editorRouter); @@ -40,12 +42,14 @@ app.use(pdfToExcel); app.use(pdfToPpt); app.use(pdfToPng); app.use(pdfToJpg); -app.use(pdfToJson) -app.use(pdfToTiff) +app.use(pdfToJson); +app.use(pdfToTiff); app.use(pdfToTxt); -app.use(wordToPdf) -app.use(express.static(path.join(__dirname, 'public'))); +app.use(wordToPdf); +app.use(compressPdf); +app.use(esign); +app.use(express.static(path.join(__dirname, "public"))); app.listen(8080, () => { - console.log('Server is running on port 8080'); + console.log("Server is running on port 8080"); }); diff --git a/package-lock.json b/package-lock.json index 98355eb..3815e0f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -35,6 +35,7 @@ "pdfjs-dist": "^3.11.174", "pdfmake": "^0.2.7", "puppeteer": "^21.6.1", + "sharp": "^0.33.5", "uuid": "^9.0.0", "xhr2": "^0.2.1", "zlib": "^1.0.5" @@ -185,6 +186,21 @@ "node": ">=4" } }, + "node_modules/@emnapi/runtime": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.2.0.tgz", + "integrity": "sha512-bV21/9LQmcQeCPEg3BDFtvwL6cwiTMksYNWQQ4KOxCZikEGalWtenoZ0wCiukJINlGCIi2KXx01g4FoH/LxpzQ==", + "optional": true, + "dependencies": { + "tslib": "^2.4.0" + } + }, + "node_modules/@emnapi/runtime/node_modules/tslib": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.7.0.tgz", + "integrity": "sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA==", + "optional": true + }, "node_modules/@foliojs-fork/fontkit": { "version": "1.9.1", "resolved": "https://registry.npmjs.org/@foliojs-fork/fontkit/-/fontkit-1.9.1.tgz", @@ -233,6 +249,348 @@ "resolved": "https://registry.npmjs.org/@foliojs-fork/restructure/-/restructure-2.0.2.tgz", "integrity": "sha512-59SgoZ3EXbkfSX7b63tsou/SDGzwUEK6MuB5sKqgVK1/XE0fxmpsOb9DQI8LXW3KfGnAjImCGhhEb7uPPAUVNA==" }, + "node_modules/@img/sharp-darwin-arm64": { + "version": "0.33.5", + "resolved": "https://registry.npmjs.org/@img/sharp-darwin-arm64/-/sharp-darwin-arm64-0.33.5.tgz", + "integrity": "sha512-UT4p+iz/2H4twwAoLCqfA9UH5pI6DggwKEGuaPy7nCVQ8ZsiY5PIcrRvD1DzuY3qYL07NtIQcWnBSY/heikIFQ==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^18.17.0 || ^20.3.0 || >=21.0.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-darwin-arm64": "1.0.4" + } + }, + "node_modules/@img/sharp-darwin-x64": { + "version": "0.33.5", + "resolved": "https://registry.npmjs.org/@img/sharp-darwin-x64/-/sharp-darwin-x64-0.33.5.tgz", + "integrity": "sha512-fyHac4jIc1ANYGRDxtiqelIbdWkIuQaI84Mv45KvGRRxSAa7o7d1ZKAOBaYbnepLC1WqxfpimdeWfvqqSGwR2Q==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^18.17.0 || ^20.3.0 || >=21.0.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-darwin-x64": "1.0.4" + } + }, + "node_modules/@img/sharp-libvips-darwin-arm64": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-darwin-arm64/-/sharp-libvips-darwin-arm64-1.0.4.tgz", + "integrity": "sha512-XblONe153h0O2zuFfTAbQYAX2JhYmDHeWikp1LM9Hul9gVPjFY427k6dFEcOL72O01QxQsWi761svJ/ev9xEDg==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "darwin" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-darwin-x64": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-darwin-x64/-/sharp-libvips-darwin-x64-1.0.4.tgz", + "integrity": "sha512-xnGR8YuZYfJGmWPvmlunFaWJsb9T/AO2ykoP3Fz/0X5XV2aoYBPkX6xqCQvUTKKiLddarLaxpzNe+b1hjeWHAQ==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "darwin" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linux-arm": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-arm/-/sharp-libvips-linux-arm-1.0.5.tgz", + "integrity": "sha512-gvcC4ACAOPRNATg/ov8/MnbxFDJqf/pDePbBnuBDcjsI8PssmjoKMAz4LtLaVi+OnSb5FK/yIOamqDwGmXW32g==", + "cpu": [ + "arm" + ], + "optional": true, + "os": [ + "linux" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linux-arm64": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-arm64/-/sharp-libvips-linux-arm64-1.0.4.tgz", + "integrity": "sha512-9B+taZ8DlyyqzZQnoeIvDVR/2F4EbMepXMc/NdVbkzsJbzkUjhXv/70GQJ7tdLA4YJgNP25zukcxpX2/SueNrA==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linux-s390x": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-s390x/-/sharp-libvips-linux-s390x-1.0.4.tgz", + "integrity": "sha512-u7Wz6ntiSSgGSGcjZ55im6uvTrOxSIS8/dgoVMoiGE9I6JAfU50yH5BoDlYA1tcuGS7g/QNtetJnxA6QEsCVTA==", + "cpu": [ + "s390x" + ], + "optional": true, + "os": [ + "linux" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linux-x64": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-x64/-/sharp-libvips-linux-x64-1.0.4.tgz", + "integrity": "sha512-MmWmQ3iPFZr0Iev+BAgVMb3ZyC4KeFc3jFxnNbEPas60e1cIfevbtuyf9nDGIzOaW9PdnDciJm+wFFaTlj5xYw==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linuxmusl-arm64": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linuxmusl-arm64/-/sharp-libvips-linuxmusl-arm64-1.0.4.tgz", + "integrity": "sha512-9Ti+BbTYDcsbp4wfYib8Ctm1ilkugkA/uscUn6UXK1ldpC1JjiXbLfFZtRlBhjPZ5o1NCLiDbg8fhUPKStHoTA==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-libvips-linuxmusl-x64": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@img/sharp-libvips-linuxmusl-x64/-/sharp-libvips-linuxmusl-x64-1.0.4.tgz", + "integrity": "sha512-viYN1KX9m+/hGkJtvYYp+CCLgnJXwiQB39damAO7WMdKWlIhmYTfHjwSbQeUK/20vY154mwezd9HflVFM1wVSw==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-linux-arm": { + "version": "0.33.5", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-arm/-/sharp-linux-arm-0.33.5.tgz", + "integrity": "sha512-JTS1eldqZbJxjvKaAkxhZmBqPRGmxgu+qFKSInv8moZ2AmT5Yib3EQ1c6gp493HvrvV8QgdOXdyaIBrhvFhBMQ==", + "cpu": [ + "arm" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^18.17.0 || ^20.3.0 || >=21.0.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linux-arm": "1.0.5" + } + }, + "node_modules/@img/sharp-linux-arm64": { + "version": "0.33.5", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-arm64/-/sharp-linux-arm64-0.33.5.tgz", + "integrity": "sha512-JMVv+AMRyGOHtO1RFBiJy/MBsgz0x4AWrT6QoEVVTyh1E39TrCUpTRI7mx9VksGX4awWASxqCYLCV4wBZHAYxA==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^18.17.0 || ^20.3.0 || >=21.0.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linux-arm64": "1.0.4" + } + }, + "node_modules/@img/sharp-linux-s390x": { + "version": "0.33.5", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-s390x/-/sharp-linux-s390x-0.33.5.tgz", + "integrity": "sha512-y/5PCd+mP4CA/sPDKl2961b+C9d+vPAveS33s6Z3zfASk2j5upL6fXVPZi7ztePZ5CuH+1kW8JtvxgbuXHRa4Q==", + "cpu": [ + "s390x" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^18.17.0 || ^20.3.0 || >=21.0.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linux-s390x": "1.0.4" + } + }, + "node_modules/@img/sharp-linux-x64": { + "version": "0.33.5", + "resolved": "https://registry.npmjs.org/@img/sharp-linux-x64/-/sharp-linux-x64-0.33.5.tgz", + "integrity": "sha512-opC+Ok5pRNAzuvq1AG0ar+1owsu842/Ab+4qvU879ippJBHvyY5n2mxF1izXqkPYlGuP/M556uh53jRLJmzTWA==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^18.17.0 || ^20.3.0 || >=21.0.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linux-x64": "1.0.4" + } + }, + "node_modules/@img/sharp-linuxmusl-arm64": { + "version": "0.33.5", + "resolved": "https://registry.npmjs.org/@img/sharp-linuxmusl-arm64/-/sharp-linuxmusl-arm64-0.33.5.tgz", + "integrity": "sha512-XrHMZwGQGvJg2V/oRSUfSAfjfPxO+4DkiRh6p2AFjLQztWUuY/o8Mq0eMQVIY7HJ1CDQUJlxGGZRw1a5bqmd1g==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^18.17.0 || ^20.3.0 || >=21.0.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linuxmusl-arm64": "1.0.4" + } + }, + "node_modules/@img/sharp-linuxmusl-x64": { + "version": "0.33.5", + "resolved": "https://registry.npmjs.org/@img/sharp-linuxmusl-x64/-/sharp-linuxmusl-x64-0.33.5.tgz", + "integrity": "sha512-WT+d/cgqKkkKySYmqoZ8y3pxx7lx9vVejxW/W4DOFMYVSkErR+w7mf2u8m/y4+xHe7yY9DAXQMWQhpnMuFfScw==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": "^18.17.0 || ^20.3.0 || >=21.0.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-libvips-linuxmusl-x64": "1.0.4" + } + }, + "node_modules/@img/sharp-wasm32": { + "version": "0.33.5", + "resolved": "https://registry.npmjs.org/@img/sharp-wasm32/-/sharp-wasm32-0.33.5.tgz", + "integrity": "sha512-ykUW4LVGaMcU9lu9thv85CbRMAwfeadCJHRsg2GmeRa/cJxsVY9Rbd57JcMxBkKHag5U/x7TSBpScF4U8ElVzg==", + "cpu": [ + "wasm32" + ], + "optional": true, + "dependencies": { + "@emnapi/runtime": "^1.2.0" + }, + "engines": { + "node": "^18.17.0 || ^20.3.0 || >=21.0.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-win32-ia32": { + "version": "0.33.5", + "resolved": "https://registry.npmjs.org/@img/sharp-win32-ia32/-/sharp-win32-ia32-0.33.5.tgz", + "integrity": "sha512-T36PblLaTwuVJ/zw/LaH0PdZkRz5rd3SmMHX8GSmR7vtNSP5Z6bQkExdSK7xGWyxLw4sUknBuugTelgw2faBbQ==", + "cpu": [ + "ia32" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": "^18.17.0 || ^20.3.0 || >=21.0.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, + "node_modules/@img/sharp-win32-x64": { + "version": "0.33.5", + "resolved": "https://registry.npmjs.org/@img/sharp-win32-x64/-/sharp-win32-x64-0.33.5.tgz", + "integrity": "sha512-MpY/o8/8kj+EcnxwvrP4aTJSWw/aZ7JIGR4aBeZkZw5B7/Jn+tY9/VNwtcoGmdT7GfggGIU4kygOMSbYnOrAbg==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": "^18.17.0 || ^20.3.0 || >=21.0.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + } + }, "node_modules/@jimp/bmp": { "version": "0.22.7", "resolved": "https://registry.npmjs.org/@jimp/bmp/-/bmp-0.22.7.tgz", @@ -1377,6 +1735,18 @@ "node": ">=0.8" } }, + "node_modules/color": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/color/-/color-4.2.3.tgz", + "integrity": "sha512-1rXeuUUiGGrykh+CeBdu5Ie7OJwinCgQY0bc7GCRxy5xVHy+moaqkpL/jqQq0MtQOeYcrqEz4abc5f0KtU7W4A==", + "dependencies": { + "color-convert": "^2.0.1", + "color-string": "^1.9.0" + }, + "engines": { + "node": ">=12.5.0" + } + }, "node_modules/color-convert": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", @@ -1393,6 +1763,15 @@ "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" }, + "node_modules/color-string": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/color-string/-/color-string-1.9.1.tgz", + "integrity": "sha512-shrVawQFojnZv6xM40anx4CkoDP+fZsw/ZerEMsW/pyzsRbElpsL/DBVW7q3ExxwusdNXI3lXpuhEZkzs8p5Eg==", + "dependencies": { + "color-name": "^1.0.0", + "simple-swizzle": "^0.2.2" + } + }, "node_modules/color-support": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/color-support/-/color-support-1.1.3.tgz", @@ -1829,9 +2208,9 @@ } }, "node_modules/detect-libc": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.2.tgz", - "integrity": "sha512-UX6sGumvvqSaXgdKGUsgZWqcUyIXZ/vZTrlRT/iobiKhGL0zL4d3osHj3uqllWJK+i+sixDS/3COVEOFbupFyw==", + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.3.tgz", + "integrity": "sha512-bwy0MGW55bG41VqxxypOsdSdGqLwXPI/focwgTYCFMbdUiBAxLg9CFzG08sz2aqzknwiX7Hkl0bQENjg8iLByw==", "engines": { "node": ">=8" } @@ -3393,17 +3772,6 @@ "underscore": "^1.13.1" } }, - "node_modules/lru-cache": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", - "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", - "dependencies": { - "yallist": "^4.0.0" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/magic-string": { "version": "0.25.1", "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.1.tgz", @@ -4836,12 +5204,9 @@ } }, "node_modules/semver": { - "version": "7.5.4", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", - "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", - "dependencies": { - "lru-cache": "^6.0.0" - }, + "version": "7.6.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", + "integrity": "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==", "bin": { "semver": "bin/semver.js" }, @@ -4938,6 +5303,44 @@ "resolved": "https://registry.npmjs.org/shallow-copy/-/shallow-copy-0.0.1.tgz", "integrity": "sha512-b6i4ZpVuUxB9h5gfCxPiusKYkqTMOjEbBs4wMaFbkfia4yFv92UKZ6Df8WXcKbn08JNL/abvg3FnMAOfakDvUw==" }, + "node_modules/sharp": { + "version": "0.33.5", + "resolved": "https://registry.npmjs.org/sharp/-/sharp-0.33.5.tgz", + "integrity": "sha512-haPVm1EkS9pgvHrQ/F3Xy+hgcuMV0Wm9vfIBSiwZ05k+xgb0PkBQpGsAA/oWdDobNaZTH5ppvHtzCFbnSEwHVw==", + "hasInstallScript": true, + "dependencies": { + "color": "^4.2.3", + "detect-libc": "^2.0.3", + "semver": "^7.6.3" + }, + "engines": { + "node": "^18.17.0 || ^20.3.0 || >=21.0.0" + }, + "funding": { + "url": "https://opencollective.com/libvips" + }, + "optionalDependencies": { + "@img/sharp-darwin-arm64": "0.33.5", + "@img/sharp-darwin-x64": "0.33.5", + "@img/sharp-libvips-darwin-arm64": "1.0.4", + "@img/sharp-libvips-darwin-x64": "1.0.4", + "@img/sharp-libvips-linux-arm": "1.0.5", + "@img/sharp-libvips-linux-arm64": "1.0.4", + "@img/sharp-libvips-linux-s390x": "1.0.4", + "@img/sharp-libvips-linux-x64": "1.0.4", + "@img/sharp-libvips-linuxmusl-arm64": "1.0.4", + "@img/sharp-libvips-linuxmusl-x64": "1.0.4", + "@img/sharp-linux-arm": "0.33.5", + "@img/sharp-linux-arm64": "0.33.5", + "@img/sharp-linux-s390x": "0.33.5", + "@img/sharp-linux-x64": "0.33.5", + "@img/sharp-linuxmusl-arm64": "0.33.5", + "@img/sharp-linuxmusl-x64": "0.33.5", + "@img/sharp-wasm32": "0.33.5", + "@img/sharp-win32-ia32": "0.33.5", + "@img/sharp-win32-x64": "0.33.5" + } + }, "node_modules/side-channel": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz", @@ -4985,6 +5388,19 @@ "simple-concat": "^1.0.0" } }, + "node_modules/simple-swizzle": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/simple-swizzle/-/simple-swizzle-0.2.2.tgz", + "integrity": "sha512-JA//kQgZtbuY83m+xT+tXJkmJncGMTFT+C+g2h2R9uxkYIrE2yy9sgmcLhCnw57/WSD+Eh3J97FPEDFnbXnDUg==", + "dependencies": { + "is-arrayish": "^0.3.1" + } + }, + "node_modules/simple-swizzle/node_modules/is-arrayish": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.3.2.tgz", + "integrity": "sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ==" + }, "node_modules/slash": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", diff --git a/package.json b/package.json index 79c2c50..94d609b 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "pdfjs-dist": "^3.11.174", "pdfmake": "^0.2.7", "puppeteer": "^21.6.1", + "sharp": "^0.33.5", "uuid": "^9.0.0", "xhr2": "^0.2.1", "zlib": "^1.0.5" diff --git a/public/js/merge.js b/public/js/merge.js index 410d1d6..c3806a6 100644 --- a/public/js/merge.js +++ b/public/js/merge.js @@ -1,993 +1,75 @@ - // █▀█ █▀▄ █▀▀   █▀▄▀█ █▀▀ █▀█ █▀▀ █▀▀ █▀█   ░░█ ▄▀█ █░█ ▄▀█ █▀▀ █▀█ █ █▀█ ▀█▀   █▀▀ █▀█ █▀▄ █▀▀ // █▀▀ █▄▀ █▀░   █░▀░█ ██▄ █▀▄ █▄█ ██▄ █▀▄   █▄█ █▀█ ▀▄▀ █▀█ █▄▄ █▀▄ █ █▀▀ ░█░   █▄▄ █▄█ █▄▀ ██▄ - $(document).ready(function () { - // When a file is selected - $('input[name="pdfs"]').change(function () { - // Get the selected files - var files = $(this)[0].files; - - // Loop through each file - for (var i = 0; i < files.length; i++) { - // Create a URL for the selected file - var url = URL.createObjectURL(files[i]); - - // Add the PDF file to the list - addPdfToList(files[i].name, url); - - } - }); + // When a file is selected + $('input[name="pdfs"]').change(function () { + // Get the selected files + var files = $(this)[0].files; + + // Loop through each file + for (var i = 0; i < files.length; i++) { + // Create a URL for the selected file + var url = URL.createObjectURL(files[i]); + + // Add the PDF file to the list + addPdfToList(files[i].name, url); + } + }); }); function addPdfToList(name, url) { - - // Create a list item element - - // Append the h1 tag to the pdfhead div only if it doesn't exist - var pdfHead = $('.pdfhead'); - if (pdfHead.children('h1').length === 0) { - var h1 = $('

', { - text: 'Selected PDFs' - }); - pdfHead.append(h1); - } - - var li = document.createElement("li"); - li.className = "list-group-item d-flex justify-content-between align-items-center"; - // Check if this is the first item in the list - - // Create a link element with the name of the file and the URL as the href attribute - var a = document.createElement("a"); - a.innerText = name; - a.href = url; - a.target = "_blank"; - - - // Create a delete button element - var button = document.createElement("button"); - button.innerText = "Delete"; - button.className = "btn btn-danger" - button.onclick = function () { - // Remove the list item from the list - li.remove(); - // Remove the corresponding file from the input field - var input = $('input[name="pdfs"]'); - var files = input[0].files; - var newFiles = []; - for (var i = 0; i < files.length; i++) { - if (files[i].name !== name) { - newFiles.push(files[i]); - } - } - input[0].files = newFiles; - }; - - // Add the link and delete button to the list item - li.appendChild(a); - li.appendChild(button); - // Add margin to the link and delete button - a.style.marginRight = "10px"; - a.style.textDecoration = "none"; - button.style.marginLeft = "10px"; - // Add the list item to the list - document.getElementById("pdf-list").appendChild(li); + // Create a list item element + + // Append the h1 tag to the pdfhead div only if it doesn't exist + var pdfHead = $(".pdfhead"); + if (pdfHead.children("h1").length === 0) { + var h1 = $("

", { + text: "Selected PDFs", + }); + pdfHead.append(h1); + } + + var li = document.createElement("li"); + li.className = + "list-group-item d-flex justify-content-between align-items-center"; + // Check if this is the first item in the list + + // Create a link element with the name of the file and the URL as the href attribute + var a = document.createElement("a"); + a.innerText = name; + a.href = url; + a.target = "_blank"; + + // Create a delete button element + var button = document.createElement("button"); + button.innerText = "Delete"; + button.className = "btn btn-danger"; + button.onclick = function () { + // Remove the list item from the list + li.remove(); + // Remove the corresponding file from the input field + var input = $('input[name="pdfs"]'); + var files = input[0].files; + var newFiles = []; + for (var i = 0; i < files.length; i++) { + if (files[i].name !== name) { + newFiles.push(files[i]); + } + } + input[0].files = newFiles; + }; + + // Add the link and delete button to the list item + li.appendChild(a); + li.appendChild(button); + // Add margin to the link and delete button + a.style.marginRight = "10px"; + a.style.textDecoration = "none"; + button.style.marginLeft = "10px"; + // Add the list item to the list + document.getElementById("pdf-list").appendChild(li); } - - // █▀█ █▀▄ █▀▀   █▀▄▀█ █▀▀ █▀█ █▀▀ █▀▀ █▀█   ░░█ ▄▀█ █░█ ▄▀█ █▀▀ █▀█ █ █▀█ ▀█▀   █▀▀ █▀█ █▀▄ █▀▀   █▀▀ █▄░█ █▀▄ // █▀▀ █▄▀ █▀░   █░▀░█ ██▄ █▀▄ █▄█ ██▄ █▀▄   █▄█ █▀█ ▀▄▀ █▀█ █▄▄ █▀▄ █ █▀▀ ░█░   █▄▄ █▄█ █▄▀ ██▄   ██▄ █░▀█ █▄▀ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/routes/compress.js b/routes/compress.js new file mode 100644 index 0000000..2a646c0 --- /dev/null +++ b/routes/compress.js @@ -0,0 +1,81 @@ +const express = require("express"); +const multer = require("multer"); +const fs = require("fs"); +const { PDFDocument } = require("pdf-lib"); +const sharp = require("sharp"); +const router = express.Router(); +const pdf2pic = require("pdf2pic"); + +const upload = multer({ dest: "uploads/" }); +router.get("/compress-pdf", (req, res) => { + res.render("compress"); +}); + +router.post("/compress", upload.single("pdfFile"), async (req, res) => { + const pdfBuffer = fs.readFileSync(req.file.path); + const pdfDoc = await PDFDocument.load(pdfBuffer); + + // Remove metadata + pdfDoc.setTitle(""); + pdfDoc.setAuthor(""); + pdfDoc.setSubject(""); + pdfDoc.setKeywords([]); + pdfDoc.setProducer(""); + pdfDoc.setCreator(""); + + // Convert PDF pages to images, compress them, and add them back to a new PDF + const newPdfDoc = await PDFDocument.create(); + const pageCount = pdfDoc.getPages().length; + + // Configure pdf2pic options + const pdf2picOptions = { + format: "png", + size: "600x600", + density: 72, + savePath: "./temp-images", + }; + const converter = pdf2pic(pdf2picOptions); + + for (let i = 0; i < pageCount; i++) { + const page = pdfDoc.getPages()[i]; + const { width, height } = page.getSize(); + + // Convert PDF page to PNG image using pdf2pic + const imagePath = await converter.convertBulk(page, -1); + + // Read PNG image into buffer + const pngImage = fs.readFileSync(imagePath); + + // Compress image using Sharp + const compressedImage = await sharp(pngImage) + .resize(width, height, { fit: "inside" }) + .jpeg({ quality: 50 }) + .toBuffer(); + + // Add compressed image to new PDF document + const newImage = await newPdfDoc.embedJpg(compressedImage); + const newPage = newPdfDoc.addPage([width, height]); + newPage.drawImage(newImage, { + x: 0, + y: 0, + width, + height, + }); + + // Delete temporary PNG image + fs.unlinkSync(imagePath); + } + + const compressedPdfBytes = await newPdfDoc.save(); + fs.writeFileSync("compressed.pdf", compressedPdfBytes); + + // Clean up uploaded file + fs.unlinkSync(req.file.path); + + res.download("compressed.pdf", "compressed.pdf", (err) => { + if (err) throw err; + fs.unlinkSync("compressed.pdf"); + }); +}); + +module.exports = router; diff --git a/routes/esign.js b/routes/esign.js new file mode 100644 index 0000000..318a694 --- /dev/null +++ b/routes/esign.js @@ -0,0 +1,66 @@ +const express = require("express"); +const multer = require("multer"); +const { PDFDocument, rgb } = require("pdf-lib"); +const fs = require("fs"); +const path = require("path"); + +const router = express.Router(); + +// Multer configuration for file upload +const upload = multer({ dest: "uploads/" }); + +router.get("/esign-pdf", (req, res) => { + res.render("esign"); // Ensure this ejs file exists in your views +}); + +router.post("/esign", upload.single("pdfFile"), async (req, res) => { + try { + // Extract file and form data + const { signatureText, fontSize, color, xPos, yPos } = req.body; + const pdfPath = req.file.path; + + // Read the uploaded PDF file + const pdfBytes = fs.readFileSync(pdfPath); + + // Load the PDF document + const pdfDoc = await PDFDocument.load(pdfBytes); + const pages = pdfDoc.getPages(); + const firstPage = pages[0]; + + // Convert color from string to RGB array + const [r, g, b] = color.split(",").map(Number); + + // Add text to the first page + firstPage.drawText(signatureText, { + x: parseInt(xPos, 10), + y: parseInt(yPos, 10), + size: parseInt(fontSize, 10), + color: rgb(r, g, b), + }); + + // Save the signed PDF + const signedPdfBytes = await pdfDoc.save(); + const signedPdfPath = path.join( + __dirname, + "../uploads/signed_" + req.file.originalname + ); + fs.writeFileSync(signedPdfPath, signedPdfBytes); + + // Send the signed PDF back to the client or download + res.download(signedPdfPath, (err) => { + if (err) { + console.error("Error sending file:", err); + res.status(500).send("Error signing the PDF"); + } + + // Clean up uploaded files + fs.unlinkSync(pdfPath); + fs.unlinkSync(signedPdfPath); + }); + } catch (error) { + console.error("Error processing PDF:", error); + res.status(500).send("Error processing the PDF"); + } +}); + +module.exports = router; diff --git a/routes/merge.js b/routes/merge.js index 8ac22ae..7ad7220 100644 --- a/routes/merge.js +++ b/routes/merge.js @@ -1,17 +1,17 @@ -const express = require('express'); +const express = require("express"); const router = express.Router(); -const { PDFDocument } = require('pdf-lib'); -const multer = require('multer'); -const fs = require('fs'); -const path = require('path'); +const { PDFDocument } = require("pdf-lib"); +const multer = require("multer"); +const fs = require("fs"); +const path = require("path"); // Set up the middleware for handling file uploads const upload = multer({ storage: multer.memoryStorage(), // Use memory storage limits: { fileSize: 10 * 1024 * 1024 }, fileFilter: (req, file, cb) => { - if (file.mimetype !== 'application/pdf') { - return cb(new Error('Only PDF files are allowed')); + if (file.mimetype !== "application/pdf") { + return cb(new Error("Only PDF files are allowed")); } cb(null, true); }, @@ -19,46 +19,48 @@ const upload = multer({ let pdfFiles = []; -router.get('/', (req, res) => { - res.render('index', { pdfFiles }); +router.get("/", (req, res) => { + res.render("index", { pdfFiles }); }); -router.post('/merge', upload.array('pdfs'), async (req, res) => { +router.post("/merge", upload.array("pdfs"), async (req, res) => { + console.log("merger click"); try { const pdfs = req.files.map((file) => file.buffer); const mergedPdf = await mergePdfs(pdfs); // Send the merged PDF file as a response - const fileName = 'merged.pdf'; + const fileName = "merged.pdf"; res.set({ - 'Content-Type': 'application/pdf', - 'Content-Disposition': `attachment; filename="${fileName}"`, + "Content-Type": "application/pdf", + "Content-Disposition": `attachment; filename="${fileName}"`, }); res.send(Buffer.from(mergedPdf)); - + // Store the uploaded PDF files in an array for display on the page pdfFiles = req.files.map((file) => file.originalname); } catch (err) { console.error(err); - res.status(500).send('An error occurred while merging the PDFs'); + res.status(500).send("An error occurred while merging the PDFs"); } }); - - // Set up the route for deleting uploaded PDF files -router.get('/delete/:index', (req, res) => { +router.get("/delete/:index", (req, res) => { const { index } = req.params; const fileName = pdfFiles[index]; pdfFiles.splice(index, 1); - res.redirect('/'); + res.redirect("/"); }); async function mergePdfs(pdfs) { const mergedPdf = await PDFDocument.create(); for (const pdf of pdfs) { const sourcePdf = await PDFDocument.load(pdf); - const pages = await mergedPdf.copyPages(sourcePdf, sourcePdf.getPageIndices()); + const pages = await mergedPdf.copyPages( + sourcePdf, + sourcePdf.getPageIndices() + ); for (const page of pages) { mergedPdf.addPage(page); } diff --git a/test.js b/test.js index 375f2b4..2a646c0 100644 --- a/test.js +++ b/test.js @@ -1,28 +1,27 @@ -const express = require('express'); -const multer = require('multer'); -const path = require('path'); -const fs = require('fs'); -const { PDFDocument } = require('pdf-lib'); -const sharp = require('sharp'); +const express = require("express"); +const multer = require("multer"); +const fs = require("fs"); +const { PDFDocument } = require("pdf-lib"); +const sharp = require("sharp"); const router = express.Router(); -const pdf2pic = require('pdf2pic'); +const pdf2pic = require("pdf2pic"); -const upload = multer({ dest: 'uploads/' }); -router.get('/compress-pdf', (req, res) => { - res.render('compress'); +const upload = multer({ dest: "uploads/" }); +router.get("/compress-pdf", (req, res) => { + res.render("compress"); }); -router.post('/compress', upload.single('pdfFile'), async (req, res) => { +router.post("/compress", upload.single("pdfFile"), async (req, res) => { const pdfBuffer = fs.readFileSync(req.file.path); const pdfDoc = await PDFDocument.load(pdfBuffer); // Remove metadata - pdfDoc.setTitle(''); - pdfDoc.setAuthor(''); - pdfDoc.setSubject(''); + pdfDoc.setTitle(""); + pdfDoc.setAuthor(""); + pdfDoc.setSubject(""); pdfDoc.setKeywords([]); - pdfDoc.setProducer(''); - pdfDoc.setCreator(''); + pdfDoc.setProducer(""); + pdfDoc.setCreator(""); // Convert PDF pages to images, compress them, and add them back to a new PDF const newPdfDoc = await PDFDocument.create(); @@ -30,10 +29,10 @@ router.post('/compress', upload.single('pdfFile'), async (req, res) => { // Configure pdf2pic options const pdf2picOptions = { - format: 'png', - size: '600x600', + format: "png", + size: "600x600", density: 72, - savePath: './temp-images', + savePath: "./temp-images", }; const converter = pdf2pic(pdf2picOptions); @@ -49,7 +48,7 @@ router.post('/compress', upload.single('pdfFile'), async (req, res) => { // Compress image using Sharp const compressedImage = await sharp(pngImage) - .resize(width, height, { fit: 'inside' }) + .resize(width, height, { fit: "inside" }) .jpeg({ quality: 50 }) .toBuffer(); @@ -68,15 +67,15 @@ router.post('/compress', upload.single('pdfFile'), async (req, res) => { } const compressedPdfBytes = await newPdfDoc.save(); - fs.writeFileSync('compressed.pdf', compressedPdfBytes); + fs.writeFileSync("compressed.pdf", compressedPdfBytes); // Clean up uploaded file fs.unlinkSync(req.file.path); - res.download('compressed.pdf', 'compressed.pdf', (err) => { + res.download("compressed.pdf", "compressed.pdf", (err) => { if (err) throw err; - fs.unlinkSync('compressed.pdf'); + fs.unlinkSync("compressed.pdf"); }); }); -module.exports = router; \ No newline at end of file +module.exports = router; diff --git a/views/compress.ejs b/views/compress.ejs index 67c618f..b0837e7 100644 --- a/views/compress.ejs +++ b/views/compress.ejs @@ -4,12 +4,69 @@ PDF Compression Tool + + + + + + + + + + -

PDF Compression Tool

-
- - -
+ + <%- include('includes/nav.ejs') %> + + +
+

+ PDF Compression Tool +

+
+ Compress large PDF files with ease +
+
+
+
+
+ PDF Icon + + +
+

+ +
+
+
+
+ + + <%- include('includes/alltools.ejs') %> <%- include('includes/services.ejs') + %> <%- include('includes/howto.ejs') %> <%- include('includes/footer.ejs') + %> + + + - \ No newline at end of file + diff --git a/views/delete.ejs b/views/delete.ejs index d759eac..28c0d9e 100644 --- a/views/delete.ejs +++ b/views/delete.ejs @@ -1,58 +1,101 @@ - - - PDF Verse - Delete PDF pages PDF online - - - - - - - - - + + + PDF Verse - Delete PDF pages PDF online + + + + + + + + + <%- include('includes/nav.ejs') %> - +
-

Delete PDF Pages

-
Remove PDF pages online and save result as new PDF
-
-
-
-
-
- - - -


- -
-
- -
-
-
-
    -
    +

    + Delete PDF Pages +

    +
    + Remove PDF pages online and save result as new PDF +
    +
    +
    +
    +
    +
    + + +
    +

    + +
    + +
    +
    +
    +
      +
      - - - - <%- include('includes/alltools.ejs') %> - - <%- include('includes/services.ejs') %> - - <%- include('includes/howto.ejs') %> +
      - <%- include('includes/footer.ejs') %> + <%- include('includes/alltools.ejs') %> <%- include('includes/services.ejs') + %> <%- include('includes/howto.ejs') %> <%- include('includes/footer.ejs') + %> - - - + + + diff --git a/views/esign.ejs b/views/esign.ejs new file mode 100644 index 0000000..2fab810 --- /dev/null +++ b/views/esign.ejs @@ -0,0 +1,167 @@ + + + + + + eSign PDF + + + + + + + + + + + + + + + + + <%- include('includes/nav.ejs') %> + + +
      +

      + eSign PDF +

      +
      + Sign and Secure Your PDF Documents with Ease +
      +
      +
      +
      +
      +
      + PDF + + +
      +
      + + +
      + + +
      +
      + + +
      +
      + + +
      +
      + + +
      +
      + + +
      + + +
      +
      +
      +
      + + + <%- include('includes/alltools.ejs') %> + + + <%- include('includes/services.ejs') %> + + + <%- include('includes/howto.ejs') %> + + + <%- include('includes/footer.ejs') %> + + + + + diff --git a/views/includes/nav.ejs b/views/includes/nav.ejs index 13ef758..46c13bf 100644 --- a/views/includes/nav.ejs +++ b/views/includes/nav.ejs @@ -1,370 +1,445 @@ + + + + + + + + + - - - - - - - - - + + - - - - - \ No newline at end of file + + + diff --git a/views/merge.ejs b/views/merge.ejs index 48c6f5c..8fd12e8 100644 --- a/views/merge.ejs +++ b/views/merge.ejs @@ -1,26 +1,29 @@ - + Merge PDFs -

      Merge PDFs

      - + <% if (pdfFiles && pdfFiles.length > 0) { %> -

      Uploaded PDF files:

      - -
      - - -
      +

      Uploaded PDF files:

      + +
      + + +
      <% } else { %> -

      No PDF files uploaded yet.

      +

      No PDF files uploaded yet.

      <% } %>