From 542d74b9cce1f1800ac89889b8712380aa0253ee Mon Sep 17 00:00:00 2001 From: Felix Kaspar Date: Mon, 16 Oct 2023 23:11:33 +0200 Subject: [PATCH 01/20] MVP - Scale Pages, Scale Content --- .gitignore | 2 + index.js | 17 ++ package-lock.json | 435 +++++++++++++++++++++++++++++++ package.json | 14 + pdfjs.code-workspace | 8 + public/functions/scaleContent.js | 29 +++ public/functions/scalePage.js | 31 +++ public/index.css | 0 public/index.html | 17 ++ public/index.js | 16 ++ 10 files changed, 569 insertions(+) create mode 100644 .gitignore create mode 100644 index.js create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 pdfjs.code-workspace create mode 100644 public/functions/scaleContent.js create mode 100644 public/functions/scalePage.js create mode 100644 public/index.css create mode 100644 public/index.html create mode 100644 public/index.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..fb7b616cf --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/node_modules/ +.env \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 000000000..497d9871d --- /dev/null +++ b/index.js @@ -0,0 +1,17 @@ + +const express = require('express'); +const app = express(); +const path = require('path'); +const PORT = 8080; + +// Static Middleware +app.use(express.static(path.join(__dirname, 'public'))) + +app.get('/', function (req, res, next) { + res.render('home.ejs'); +}) + +app.listen(PORT, function (err) { + if (err) console.log(err); + console.log(`http://localhost:${PORT}`); +}); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 000000000..20c4e1e28 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,435 @@ +{ + "name": "pdfjs", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "accepts": { + "version": "1.3.8", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", + "integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==", + "requires": { + "mime-types": "~2.1.34", + "negotiator": "0.6.3" + } + }, + "array-flatten": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", + "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==" + }, + "body-parser": { + "version": "1.20.1", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz", + "integrity": "sha512-jWi7abTbYwajOytWCQc37VulmWiRae5RyTpaCyDcS5/lMdtwSz5lOpDE67srw/HYe35f1z3fDQw+3txg7gNtWw==", + "requires": { + "bytes": "3.1.2", + "content-type": "~1.0.4", + "debug": "2.6.9", + "depd": "2.0.0", + "destroy": "1.2.0", + "http-errors": "2.0.0", + "iconv-lite": "0.4.24", + "on-finished": "2.4.1", + "qs": "6.11.0", + "raw-body": "2.5.1", + "type-is": "~1.6.18", + "unpipe": "1.0.0" + } + }, + "bytes": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", + "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==" + }, + "call-bind": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz", + "integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==", + "requires": { + "function-bind": "^1.1.1", + "get-intrinsic": "^1.0.2" + } + }, + "content-disposition": { + "version": "0.5.4", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz", + "integrity": "sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==", + "requires": { + "safe-buffer": "5.2.1" + } + }, + "content-type": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz", + "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==" + }, + "cookie": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.5.0.tgz", + "integrity": "sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw==" + }, + "cookie-signature": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", + "integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ==" + }, + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "requires": { + "ms": "2.0.0" + } + }, + "depd": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", + "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==" + }, + "destroy": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz", + "integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==" + }, + "ee-first": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", + "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==" + }, + "encodeurl": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", + "integrity": "sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w==" + }, + "escape-html": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", + "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==" + }, + "etag": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", + "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==" + }, + "express": { + "version": "4.18.2", + "resolved": "https://registry.npmjs.org/express/-/express-4.18.2.tgz", + "integrity": "sha512-5/PsL6iGPdfQ/lKM1UuielYgv3BUoJfz1aUwU9vHZ+J7gyvwdQXFEBIEIaxeGf0GIcreATNyBExtalisDbuMqQ==", + "requires": { + "accepts": "~1.3.8", + "array-flatten": "1.1.1", + "body-parser": "1.20.1", + "content-disposition": "0.5.4", + "content-type": "~1.0.4", + "cookie": "0.5.0", + "cookie-signature": "1.0.6", + "debug": "2.6.9", + "depd": "2.0.0", + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "etag": "~1.8.1", + "finalhandler": "1.2.0", + "fresh": "0.5.2", + "http-errors": "2.0.0", + "merge-descriptors": "1.0.1", + "methods": "~1.1.2", + "on-finished": "2.4.1", + "parseurl": "~1.3.3", + "path-to-regexp": "0.1.7", + "proxy-addr": "~2.0.7", + "qs": "6.11.0", + "range-parser": "~1.2.1", + "safe-buffer": "5.2.1", + "send": "0.18.0", + "serve-static": "1.15.0", + "setprototypeof": "1.2.0", + "statuses": "2.0.1", + "type-is": "~1.6.18", + "utils-merge": "1.0.1", + "vary": "~1.1.2" + } + }, + "finalhandler": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.2.0.tgz", + "integrity": "sha512-5uXcUVftlQMFnWC9qu/svkWv3GTd2PfUhK/3PLkYNAe7FbqJMt3515HaxE6eRL74GdsriiwujiawdaB1BpEISg==", + "requires": { + "debug": "2.6.9", + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "on-finished": "2.4.1", + "parseurl": "~1.3.3", + "statuses": "2.0.1", + "unpipe": "~1.0.0" + } + }, + "forwarded": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", + "integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==" + }, + "fresh": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", + "integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==" + }, + "function-bind": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==" + }, + "get-intrinsic": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.1.tgz", + "integrity": "sha512-2DcsyfABl+gVHEfCOaTrWgyt+tb6MSEGmKq+kI5HwLbIYgjgmMcV8KQ41uaKz1xxUcn9tJtgFbQUEVcEbd0FYw==", + "requires": { + "function-bind": "^1.1.1", + "has": "^1.0.3", + "has-proto": "^1.0.1", + "has-symbols": "^1.0.3" + } + }, + "has": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/has/-/has-1.0.4.tgz", + "integrity": "sha512-qdSAmqLF6209RFj4VVItywPMbm3vWylknmB3nvNiUIs72xAimcM8nVYxYr7ncvZq5qzk9MKIZR8ijqD/1QuYjQ==" + }, + "has-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.1.tgz", + "integrity": "sha512-7qE+iP+O+bgF9clE5+UoBFzE65mlBiVj3tKCrlNQ0Ogwm0BjpT/gK4SlLYDMybDh5I3TCTKnPPa0oMG7JDYrhg==" + }, + "has-symbols": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", + "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==" + }, + "http-errors": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz", + "integrity": "sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==", + "requires": { + "depd": "2.0.0", + "inherits": "2.0.4", + "setprototypeof": "1.2.0", + "statuses": "2.0.1", + "toidentifier": "1.0.1" + } + }, + "iconv-lite": { + "version": "0.4.24", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", + "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", + "requires": { + "safer-buffer": ">= 2.1.2 < 3" + } + }, + "inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + }, + "ipaddr.js": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", + "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==" + }, + "media-typer": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", + "integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==" + }, + "merge-descriptors": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", + "integrity": "sha512-cCi6g3/Zr1iqQi6ySbseM1Xvooa98N0w31jzUYrXPX2xqObmFGHJ0tQ5u74H3mVh7wLouTseZyYIq39g8cNp1w==" + }, + "methods": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", + "integrity": "sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==" + }, + "mime": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", + "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==" + }, + "mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==" + }, + "mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "requires": { + "mime-db": "1.52.0" + } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" + }, + "negotiator": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", + "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==" + }, + "object-inspect": { + "version": "1.13.0", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.0.tgz", + "integrity": "sha512-HQ4J+ic8hKrgIt3mqk6cVOVrW2ozL4KdvHlqpBv9vDYWx9ysAgENAdvy4FoGF+KFdhR7nQTNm5J0ctAeOwn+3g==" + }, + "on-finished": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", + "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==", + "requires": { + "ee-first": "1.1.1" + } + }, + "parseurl": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", + "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==" + }, + "path-to-regexp": { + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", + "integrity": "sha512-5DFkuoqlv1uYQKxy8omFBeJPQcdoE07Kv2sferDCrAq1ohOU+MSDswDIbnx3YAM60qIOnYa53wBhXW0EbMonrQ==" + }, + "proxy-addr": { + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", + "integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==", + "requires": { + "forwarded": "0.2.0", + "ipaddr.js": "1.9.1" + } + }, + "qs": { + "version": "6.11.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz", + "integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==", + "requires": { + "side-channel": "^1.0.4" + } + }, + "range-parser": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", + "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==" + }, + "raw-body": { + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.1.tgz", + "integrity": "sha512-qqJBtEyVgS0ZmPGdCFPWJ3FreoqvG4MVQln/kCgF7Olq95IbOp0/BWyMwbdtn4VTvkM8Y7khCQ2Xgk/tcrCXig==", + "requires": { + "bytes": "3.1.2", + "http-errors": "2.0.0", + "iconv-lite": "0.4.24", + "unpipe": "1.0.0" + } + }, + "safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==" + }, + "safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" + }, + "send": { + "version": "0.18.0", + "resolved": "https://registry.npmjs.org/send/-/send-0.18.0.tgz", + "integrity": "sha512-qqWzuOjSFOuqPjFe4NOsMLafToQQwBSOEpS+FwEt3A2V3vKubTquT3vmLTQpFgMXp8AlFWFuP1qKaJZOtPpVXg==", + "requires": { + "debug": "2.6.9", + "depd": "2.0.0", + "destroy": "1.2.0", + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "etag": "~1.8.1", + "fresh": "0.5.2", + "http-errors": "2.0.0", + "mime": "1.6.0", + "ms": "2.1.3", + "on-finished": "2.4.1", + "range-parser": "~1.2.1", + "statuses": "2.0.1" + }, + "dependencies": { + "ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" + } + } + }, + "serve-static": { + "version": "1.15.0", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.15.0.tgz", + "integrity": "sha512-XGuRDNjXUijsUL0vl6nSD7cwURuzEgglbOaFuZM9g3kwDXOWVTck0jLzjPzGD+TazWbboZYu52/9/XPdUgne9g==", + "requires": { + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "parseurl": "~1.3.3", + "send": "0.18.0" + } + }, + "setprototypeof": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", + "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==" + }, + "side-channel": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz", + "integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==", + "requires": { + "call-bind": "^1.0.0", + "get-intrinsic": "^1.0.2", + "object-inspect": "^1.9.0" + } + }, + "statuses": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", + "integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==" + }, + "toidentifier": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", + "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==" + }, + "type-is": { + "version": "1.6.18", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", + "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==", + "requires": { + "media-typer": "0.3.0", + "mime-types": "~2.1.24" + } + }, + "unpipe": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", + "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==" + }, + "utils-merge": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", + "integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==" + }, + "vary": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", + "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 000000000..92c1624d4 --- /dev/null +++ b/package.json @@ -0,0 +1,14 @@ +{ + "name": "pdfjs", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "node ." + }, + "author": "", + "license": "ISC", + "dependencies": { + "express": "^4.18.2" + } +} diff --git a/pdfjs.code-workspace b/pdfjs.code-workspace new file mode 100644 index 000000000..517e0b2a8 --- /dev/null +++ b/pdfjs.code-workspace @@ -0,0 +1,8 @@ +{ + "folders": [ + { + "path": "." + } + ], + "settings": {} +} \ No newline at end of file diff --git a/public/functions/scaleContent.js b/public/functions/scaleContent.js new file mode 100644 index 000000000..97d56c597 --- /dev/null +++ b/public/functions/scaleContent.js @@ -0,0 +1,29 @@ +const { PDFDocument, ParseSpeeds } = PDFLib; + +export const scaleContent = async (snapshot, scale_factor) => { + // Load the original PDF file + const pdfDoc = await PDFDocument.load(snapshot, { + parseSpeed: ParseSpeeds.Fastest, + }); + + const pages = pdfDoc.getPages(); + + pages.forEach(page => { + const width = page.getWidth(); + const height = page.getHeight(); + + // Scale content + page.scaleContent(scale_factor, scale_factor); + const scaled_diff = { + width: Math.round(width - scale_factor * width), + height: Math.round(height - scale_factor * height), + }; + + // Center content in new page format + page.translateContent(Math.round(scaled_diff.width / 2), Math.round(scaled_diff.height / 2)); + + }); + + // Serialize the modified document + return pdfDoc.save(); +}; \ No newline at end of file diff --git a/public/functions/scalePage.js b/public/functions/scalePage.js new file mode 100644 index 000000000..ffa6ee9ad --- /dev/null +++ b/public/functions/scalePage.js @@ -0,0 +1,31 @@ +const { PDFDocument, ParseSpeeds } = PDFLib; + +export const scalePage = async (snapshot, page_size) => { + // Load the original PDF file + const pdfDoc = await PDFDocument.load(snapshot, { + parseSpeed: ParseSpeeds.Fastest, + }); + + const new_size = page_size; + + const pages = pdfDoc.getPages(); + + pages.forEach(page => { + // Change page size + page.setSize(new_size.width, new_size.height); + }); + + // Serialize the modified document + return pdfDoc.save(); +}; + +export const PageSize = { + a4: { + width: 594.96, + height: 841.92 + }, + letter: { + width: 612, + height: 792 + } +}; \ No newline at end of file diff --git a/public/index.css b/public/index.css new file mode 100644 index 000000000..e69de29bb diff --git a/public/index.html b/public/index.html new file mode 100644 index 000000000..0b1c102c8 --- /dev/null +++ b/public/index.html @@ -0,0 +1,17 @@ + + + + + + Document + + + + + + + + + + + \ No newline at end of file diff --git a/public/index.js b/public/index.js new file mode 100644 index 000000000..504be83c4 --- /dev/null +++ b/public/index.js @@ -0,0 +1,16 @@ +import { scaleContent } from "./functions/scaleContent.js"; +import { scalePage, PageSize } from "./functions/scalePage.js"; + +(async () => { + const pdfFileInput = document.getElementById('pdfFile'); + + pdfFileInput.addEventListener('change', async (e) => { + const file = e.target.files[0]; + if (file) { + let pdfBuffer = new Uint8Array(await file.arrayBuffer()); + pdfBuffer = await scaleContent(pdfBuffer, 2); + pdfBuffer = await scalePage(pdfBuffer, PageSize.letter); + download(pdfBuffer, "pdf-lib_creation_example.pdf", "application/pdf"); + } + }); +})(); From 76e37354e1e00b815764c4b3f998789f7a8a0378 Mon Sep 17 00:00:00 2001 From: Felix Kaspar Date: Tue, 17 Oct 2023 01:31:00 +0200 Subject: [PATCH 02/20] node based backend --- public/index.html | 15 ++- public/index.js | 194 +++++++++++++++++++++++++++++-- public/organizeWaitOperations.js | 43 +++++++ public/testWorkflow.js | 71 +++++++++++ 4 files changed, 313 insertions(+), 10 deletions(-) create mode 100644 public/organizeWaitOperations.js create mode 100644 public/testWorkflow.js diff --git a/public/index.html b/public/index.html index 0b1c102c8..ac9372364 100644 --- a/public/index.html +++ b/public/index.html @@ -12,6 +12,19 @@ - + + + + + + + \ No newline at end of file diff --git a/public/index.js b/public/index.js index 504be83c4..8190ca767 100644 --- a/public/index.js +++ b/public/index.js @@ -1,16 +1,192 @@ import { scaleContent } from "./functions/scaleContent.js"; import { scalePage, PageSize } from "./functions/scalePage.js"; +import { organizeWaitOperations } from "./organizeWaitOperations.js"; +import { testWorkflow } from "./testWorkflow.js"; -(async () => { +(async (workflow) => { const pdfFileInput = document.getElementById('pdfFile'); + const doneButton = document.getElementById("doneButton"); - pdfFileInput.addEventListener('change', async (e) => { - const file = e.target.files[0]; - if (file) { - let pdfBuffer = new Uint8Array(await file.arrayBuffer()); - pdfBuffer = await scaleContent(pdfBuffer, 2); - pdfBuffer = await scalePage(pdfBuffer, PageSize.letter); - download(pdfBuffer, "pdf-lib_creation_example.pdf", "application/pdf"); + doneButton.addEventListener('click', async (e) => { + const files = Array.from(pdfFileInput.files); + console.log(files); + const pdfBuffers = await Promise.all(files.map(async file => { + return { + originalFileName: file.name.replace(/\.[^/.]+$/, ""), + fileName: file.name.replace(/\.[^/.]+$/, ""), + buffer: new Uint8Array(await file.arrayBuffer()) + } + })); + console.log(pdfBuffers); + + const waitOperations = organizeWaitOperations(workflow.operations); + + nextOperation(workflow.operations, pdfBuffers); + + async function nextOperation(operations, input) { + if(Array.isArray(operations) && operations.length == 0) { // isEmpty + console.log("operation done: " + input.fileName); + //TODO: Download Restult + return; + } + + for (let i = 0; i < operations.length; i++) { + console.warn(input); + await computeOperation(operations[i], structuredClone(input)); // break references + } } + + async function computeOperation(operation, input) { + switch (operation.type) { + case "done": + console.log("Done operation will get called if all waits are done. Skipping for now.") + break; + case "wait": + const waitOperation = waitOperations[operation.values.id]; + waitOperation.input.push(input); + waitOperation.waitCount--; + if(waitOperation.waitCount == 0) { + await nextOperation(waitOperation.doneOperation.operations, waitOperation.input); + } + break; + case "removeObjects": + if(Array.isArray(input)) { + for (let i = 0; i < input.length; i++) { + // TODO: modfiy input + input[i].fileName += "_removedObjects"; + await nextOperation(operation.operations, input[i]); + } + } + else { + // TODO: modfiy input + input.fileName += "_removedObjects"; + await nextOperation(operation.operations, input); + } + break; + case "extract": + if(Array.isArray(input)) { + for (let i = 0; i < input.length; i++) { + // TODO: modfiy input + input[i].fileName += "_extractedPages"; + await nextOperation(operation.operations, input[i]); + } + } + else { + // TODO: modfiy input + input.fileName += "_extractedPages"; + await nextOperation(operation.operations, input); + } + break; + case "fillField": + if(Array.isArray(input)) { + for (let i = 0; i < input.length; i++) { + // TODO: modfiy input + input[i].fileName += "_filledField"; + await nextOperation(operation.operations, input[i]); + } + } + else { + // TODO: modfiy input + input.fileName += "_filledField"; + await nextOperation(operation.operations, input); + } + break; + case "extractImages": + if(Array.isArray(input)) { + for (let i = 0; i < input.length; i++) { + // TODO: modfiy input + input[i].fileName += "_extractedImages"; + await nextOperation(operation.operations, input[i]); + } + } + else { + // TODO: modfiy input + input.fileName += "_extractedImages"; + await nextOperation(operation.operations, input); + } + break; + case "merge": + if(Array.isArray(input)) { + input = { + originalFileName: input.map(input => input.originalFileName).join("_and_"), + fileName: input.map(input => input.fileName).join("_and_") + "_merged", + buffer: input[0].buffer // TODO: merge inputs + } + } + else { + // TODO: modfiy input + input.fileName += "_merged"; + } + await nextOperation(operation.operations, input); + break; + case "transform": { + if(Array.isArray(input)) { + for (let i = 0; i < input.length; i++) { + // TODO: modfiy input + input[i].fileName += "_transformed"; + await nextOperation(operation.operations, input[i]); + } + } + else { + // TODO: modfiy input + input.fileName += "_transformed"; + await nextOperation(operation.operations, input); + } + break; + } + default: + console.log("operation type unknown: ", operation.type); + break; + } + } + + + + + + // if(selectedElementsList[0].textContent == "mergePDFs") { + + // } + + // // TODO: This can also be run serverside + // if(files.length > 1) { + // files.forEach(file => { + + // }); + // } + // else { + // const file = files[0]; + // let pdfBuffer = new Uint8Array(await file.arrayBuffer()); + // if (file) { + // for (let i = 0; i < selectedElementsList.length; i++) { + // const selectedOption = selectedElementsList[i]; + + // // Perform actions based on the selected option using the switch statement + // switch (selectedOption.textContent) { + // case "scaleContent": + // pdfBuffer = await scaleContent(pdfBuffer, 2); + // break; + // case "changePageSize": + // pdfBuffer = await scalePage(pdfBuffer, PageSize.letter); + // break; + // default: + // // Handle any other actions or errors here + // throw new Error(`This action ${selectedOption.value} has not been implemented.`); + // } + // } + // download(pdfBuffer, file.name.replace(/\.[^/.]+$/, "") + "_mod.pdf", "application/pdf"); + // } + // } }); -})(); + + // document.getElementById("addButton").addEventListener("click", function() { + // const selectedOption = document.getElementById("pdfOptions").value; + // const operations = document.getElementById("operations"); + + // if (selectedOption) { + // const listItem = document.createElement("li"); + // listItem.textContent = selectedOption; + // operations.appendChild(listItem); + // } + // }); +})(testWorkflow); diff --git a/public/organizeWaitOperations.js b/public/organizeWaitOperations.js new file mode 100644 index 000000000..c994502af --- /dev/null +++ b/public/organizeWaitOperations.js @@ -0,0 +1,43 @@ + +export function organizeWaitOperations(operations) { + + // Initialize an object to store the counts and associated "done" operations + const waitCounts = {}; + const doneOperations = {}; + + // Function to count "type: wait" operations and associate "done" operations per id + function countWaitOperationsAndDone(operations) { + for (const operation of operations) { + if (operation.type === "wait") { + const id = operation.values.id; + if (id in waitCounts) { + waitCounts[id]++; + } else { + waitCounts[id] = 1; + } + } + if (operation.type === "done") { + const id = operation.values.id; + doneOperations[id] = operation; + } + if (operation.operations) { + countWaitOperationsAndDone(operation.operations); + } + } + } + + // Start counting and associating from the root operations + countWaitOperationsAndDone(operations); + + // Combine counts and associated "done" operations + const result = {}; + for (const id in waitCounts) { + result[id] = { + waitCount: waitCounts[id], + doneOperation: doneOperations[id], + input: [] + }; + } + return result; +} + diff --git a/public/testWorkflow.js b/public/testWorkflow.js new file mode 100644 index 000000000..673dfbc37 --- /dev/null +++ b/public/testWorkflow.js @@ -0,0 +1,71 @@ +// JSON Representation of this Node Tree: +// https://discord.com/channels/1068636748814483718/1099390571493195898/1118192754103693483 +// https://cdn.discordapp.com/attachments/1099390571493195898/1118192753759764520/image.png?ex=6537dba7&is=652566a7&hm=dc46820ef7c34bc37424794966c5f66f93ba0e15a740742c364d47d31ea119a9& + +export const testWorkflow = { + outputOptions: { + zip: false, + awaitAllDone: true + }, + operations: [ + { + type: "extract", + values: { "index": "1" }, + operations: [ + { + type: "removeObjects", + values: { "objectNames": "photo, josh" }, + operations: [ + { + type: "wait", + values: { "id": 1 } + } + ] + } + ] + }, + { + type: "extract", + values: { "index": "2-5" }, + operations: [ + { + type: "fillField", + values: { "objectName": "name", "inputValue": "Josh" }, + operations: [ + { + type: "wait", + values: { "id": 1 } + } + ] + } + ] + }, + { + type: "done", // This gets called when the other merge-ops with the same id finish. + values: { "id": 1 }, + operations: [ + { + type: "merge", // This gets called when the other merge-ops with the same id finish. + values: {}, + operations: [] + } + ] + }, + { + type: "extractImages", + values: {}, + operations: [] + }, + { + type: "merge", // This gets called when the other merge-ops with the same id finish. + values: {}, + operations: [ + { + type: "transform", + values: { "scale": "2x", "rotation": "90deg" }, + operations: [] + } + ] + } + ] +} \ No newline at end of file From 96bac91fa1b4aa901c6e5c049fa26b28acd664d4 Mon Sep 17 00:00:00 2001 From: Felix Kaspar Date: Tue, 17 Oct 2023 01:38:51 +0200 Subject: [PATCH 03/20] modularization --- public/index.js | 138 +---------------------------------- public/traverseOperations.js | 125 +++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+), 136 deletions(-) create mode 100644 public/traverseOperations.js diff --git a/public/index.js b/public/index.js index 8190ca767..8811c40d5 100644 --- a/public/index.js +++ b/public/index.js @@ -1,7 +1,7 @@ import { scaleContent } from "./functions/scaleContent.js"; import { scalePage, PageSize } from "./functions/scalePage.js"; -import { organizeWaitOperations } from "./organizeWaitOperations.js"; import { testWorkflow } from "./testWorkflow.js"; +import { traverseOperations } from "./traverseOperations.js"; (async (workflow) => { const pdfFileInput = document.getElementById('pdfFile'); @@ -19,130 +19,7 @@ import { testWorkflow } from "./testWorkflow.js"; })); console.log(pdfBuffers); - const waitOperations = organizeWaitOperations(workflow.operations); - - nextOperation(workflow.operations, pdfBuffers); - - async function nextOperation(operations, input) { - if(Array.isArray(operations) && operations.length == 0) { // isEmpty - console.log("operation done: " + input.fileName); - //TODO: Download Restult - return; - } - - for (let i = 0; i < operations.length; i++) { - console.warn(input); - await computeOperation(operations[i], structuredClone(input)); // break references - } - } - - async function computeOperation(operation, input) { - switch (operation.type) { - case "done": - console.log("Done operation will get called if all waits are done. Skipping for now.") - break; - case "wait": - const waitOperation = waitOperations[operation.values.id]; - waitOperation.input.push(input); - waitOperation.waitCount--; - if(waitOperation.waitCount == 0) { - await nextOperation(waitOperation.doneOperation.operations, waitOperation.input); - } - break; - case "removeObjects": - if(Array.isArray(input)) { - for (let i = 0; i < input.length; i++) { - // TODO: modfiy input - input[i].fileName += "_removedObjects"; - await nextOperation(operation.operations, input[i]); - } - } - else { - // TODO: modfiy input - input.fileName += "_removedObjects"; - await nextOperation(operation.operations, input); - } - break; - case "extract": - if(Array.isArray(input)) { - for (let i = 0; i < input.length; i++) { - // TODO: modfiy input - input[i].fileName += "_extractedPages"; - await nextOperation(operation.operations, input[i]); - } - } - else { - // TODO: modfiy input - input.fileName += "_extractedPages"; - await nextOperation(operation.operations, input); - } - break; - case "fillField": - if(Array.isArray(input)) { - for (let i = 0; i < input.length; i++) { - // TODO: modfiy input - input[i].fileName += "_filledField"; - await nextOperation(operation.operations, input[i]); - } - } - else { - // TODO: modfiy input - input.fileName += "_filledField"; - await nextOperation(operation.operations, input); - } - break; - case "extractImages": - if(Array.isArray(input)) { - for (let i = 0; i < input.length; i++) { - // TODO: modfiy input - input[i].fileName += "_extractedImages"; - await nextOperation(operation.operations, input[i]); - } - } - else { - // TODO: modfiy input - input.fileName += "_extractedImages"; - await nextOperation(operation.operations, input); - } - break; - case "merge": - if(Array.isArray(input)) { - input = { - originalFileName: input.map(input => input.originalFileName).join("_and_"), - fileName: input.map(input => input.fileName).join("_and_") + "_merged", - buffer: input[0].buffer // TODO: merge inputs - } - } - else { - // TODO: modfiy input - input.fileName += "_merged"; - } - await nextOperation(operation.operations, input); - break; - case "transform": { - if(Array.isArray(input)) { - for (let i = 0; i < input.length; i++) { - // TODO: modfiy input - input[i].fileName += "_transformed"; - await nextOperation(operation.operations, input[i]); - } - } - else { - // TODO: modfiy input - input.fileName += "_transformed"; - await nextOperation(operation.operations, input); - } - break; - } - default: - console.log("operation type unknown: ", operation.type); - break; - } - } - - - - + await traverseOperations(workflow.operations, pdfBuffers); // if(selectedElementsList[0].textContent == "mergePDFs") { @@ -178,15 +55,4 @@ import { testWorkflow } from "./testWorkflow.js"; // } // } }); - - // document.getElementById("addButton").addEventListener("click", function() { - // const selectedOption = document.getElementById("pdfOptions").value; - // const operations = document.getElementById("operations"); - - // if (selectedOption) { - // const listItem = document.createElement("li"); - // listItem.textContent = selectedOption; - // operations.appendChild(listItem); - // } - // }); })(testWorkflow); diff --git a/public/traverseOperations.js b/public/traverseOperations.js new file mode 100644 index 000000000..50ad7ad64 --- /dev/null +++ b/public/traverseOperations.js @@ -0,0 +1,125 @@ +import { organizeWaitOperations } from "./organizeWaitOperations.js"; + +export async function traverseOperations(operations, input) { + const waitOperations = organizeWaitOperations(operations); + await nextOperation(operations, input); + + async function nextOperation(operations, input) { + if(Array.isArray(operations) && operations.length == 0) { // isEmpty + console.log("operation done: " + input.fileName); + + //TODO: Delay the download + download(input, input.fileName, "application/pdf"); + return; + } + + for (let i = 0; i < operations.length; i++) { + console.warn(input); + await computeOperation(operations[i], structuredClone(input)); // break references + } + } + + async function computeOperation(operation, input) { + switch (operation.type) { + case "done": + console.log("Done operation will get called if all waits are done. Skipping for now.") + break; + case "wait": + const waitOperation = waitOperations[operation.values.id]; + waitOperation.input.push(input); + waitOperation.waitCount--; + if(waitOperation.waitCount == 0) { + await nextOperation(waitOperation.doneOperation.operations, waitOperation.input); + } + break; + case "removeObjects": + if(Array.isArray(input)) { + for (let i = 0; i < input.length; i++) { + // TODO: modfiy input + input[i].fileName += "_removedObjects"; + await nextOperation(operation.operations, input[i]); + } + } + else { + // TODO: modfiy input + input.fileName += "_removedObjects"; + await nextOperation(operation.operations, input); + } + break; + case "extract": + if(Array.isArray(input)) { + for (let i = 0; i < input.length; i++) { + // TODO: modfiy input + input[i].fileName += "_extractedPages"; + await nextOperation(operation.operations, input[i]); + } + } + else { + // TODO: modfiy input + input.fileName += "_extractedPages"; + await nextOperation(operation.operations, input); + } + break; + case "fillField": + if(Array.isArray(input)) { + for (let i = 0; i < input.length; i++) { + // TODO: modfiy input + input[i].fileName += "_filledField"; + await nextOperation(operation.operations, input[i]); + } + } + else { + // TODO: modfiy input + input.fileName += "_filledField"; + await nextOperation(operation.operations, input); + } + break; + case "extractImages": + if(Array.isArray(input)) { + for (let i = 0; i < input.length; i++) { + // TODO: modfiy input + input[i].fileName += "_extractedImages"; + await nextOperation(operation.operations, input[i]); + } + } + else { + // TODO: modfiy input + input.fileName += "_extractedImages"; + await nextOperation(operation.operations, input); + } + break; + case "merge": + if(Array.isArray(input)) { + input = { + originalFileName: input.map(input => input.originalFileName).join("_and_"), + fileName: input.map(input => input.fileName).join("_and_") + "_merged", + buffer: input[0].buffer // TODO: merge inputs + } + } + else { + // TODO: modfiy input + input.fileName += "_merged"; + } + await nextOperation(operation.operations, input); + break; + case "transform": { + if(Array.isArray(input)) { + for (let i = 0; i < input.length; i++) { + // TODO: modfiy input + input[i].fileName += "_transformed"; + await nextOperation(operation.operations, input[i]); + } + } + else { + // TODO: modfiy input + input.fileName += "_transformed"; + await nextOperation(operation.operations, input); + } + break; + } + default: + console.log("operation type unknown: ", operation.type); + break; + } + } +} \ No newline at end of file From 8e8c4596bfb8e593afdca130db977317ead0fcf7 Mon Sep 17 00:00:00 2001 From: Felix Kaspar Date: Tue, 17 Oct 2023 02:14:06 +0200 Subject: [PATCH 04/20] Fixed downloading buffer, merging workflow --- .../{testWorkflow.js => exampleWorkflows.js} | 22 +++++++++++++++---- public/functions/mergePDFs.js | 15 +++++++++++++ public/index.html | 2 +- public/index.js | 20 ++++++++--------- public/traverseOperations.js | 18 ++++++++------- 5 files changed, 54 insertions(+), 23 deletions(-) rename public/{testWorkflow.js => exampleWorkflows.js} (84%) create mode 100644 public/functions/mergePDFs.js diff --git a/public/testWorkflow.js b/public/exampleWorkflows.js similarity index 84% rename from public/testWorkflow.js rename to public/exampleWorkflows.js index 673dfbc37..61563483c 100644 --- a/public/testWorkflow.js +++ b/public/exampleWorkflows.js @@ -1,8 +1,7 @@ // JSON Representation of this Node Tree: // https://discord.com/channels/1068636748814483718/1099390571493195898/1118192754103693483 // https://cdn.discordapp.com/attachments/1099390571493195898/1118192753759764520/image.png?ex=6537dba7&is=652566a7&hm=dc46820ef7c34bc37424794966c5f66f93ba0e15a740742c364d47d31ea119a9& - -export const testWorkflow = { +export const discordWorkflow = { outputOptions: { zip: false, awaitAllDone: true @@ -45,7 +44,7 @@ export const testWorkflow = { values: { "id": 1 }, operations: [ { - type: "merge", // This gets called when the other merge-ops with the same id finish. + type: "merge", values: {}, operations: [] } @@ -57,7 +56,7 @@ export const testWorkflow = { operations: [] }, { - type: "merge", // This gets called when the other merge-ops with the same id finish. + type: "merge", values: {}, operations: [ { @@ -68,4 +67,19 @@ export const testWorkflow = { ] } ] +} + +// This will merge all input files into one giant document +export const mergeOnly = { + outputOptions: { + zip: false, + awaitAllDone: true + }, + operations: [ + { + type: "merge", + values: {}, + operations: [] + } + ] } \ No newline at end of file diff --git a/public/functions/mergePDFs.js b/public/functions/mergePDFs.js new file mode 100644 index 000000000..f243451a3 --- /dev/null +++ b/public/functions/mergePDFs.js @@ -0,0 +1,15 @@ +const { PDFDocument, ParseSpeeds } = PDFLib; + +export const mergePDFs = async (snapshots) => { + + const mergedPdf = await PDFDocument.create(); + + for (let i = 0; i < snapshots.length; i++) { + const pdfToMerge = await PDFDocument.load(snapshots[i]); + + const copiedPages = await mergedPdf.copyPages(pdfToMerge, pdfToMerge.getPageIndices()); + copiedPages.forEach((page) => mergedPdf.addPage(page)); + } + + return mergedPdf.save(); +}; \ No newline at end of file diff --git a/public/index.html b/public/index.html index ac9372364..821533bcd 100644 --- a/public/index.html +++ b/public/index.html @@ -11,7 +11,7 @@ - +