+ From b604cb63c8b4a28e4c31708460463ea492cf696e Mon Sep 17 00:00:00 2001 From: Arpit Chakladar <54011232+arpitchakladar@users.noreply.github.com> Date: Tue, 11 Apr 2023 20:37:34 +0530 Subject: Using a seperate HTML file for the generating the PDF. Putting the footer at the bottom of each page. --- config/tsconfig.json | 3 + config/webpack.config.js | 6 +- config/webpack/loader/to-string-loader.js | 41 ++++ src/html.d.ts | 3 + .../download-information-pdf-page-content.html | 273 +++++++++++++++++++++ .../download-information-pdf-page-content.ts | 219 ----------------- src/scripts/functionality/view-khatian/index.ts | 15 +- src/shared/download-pdf.ts | 17 -- src/shared/generate-web-page.ts | 9 + 9 files changed, 343 insertions(+), 243 deletions(-) create mode 100644 config/webpack/loader/to-string-loader.js create mode 100644 src/html.d.ts create mode 100644 src/scripts/functionality/view-khatian/download-information-pdf-page-content.html delete mode 100644 src/scripts/functionality/view-khatian/download-information-pdf-page-content.ts delete mode 100644 src/shared/download-pdf.ts create mode 100644 src/shared/generate-web-page.ts diff --git a/config/tsconfig.json b/config/tsconfig.json index 120bfcb..ec61595 100644 --- a/config/tsconfig.json +++ b/config/tsconfig.json @@ -1,4 +1,7 @@ { + "files": [ + "../src/html.d.ts" + ], "compilerOptions": { "outDir": "dist", "sourceMap": true, diff --git a/config/webpack.config.js b/config/webpack.config.js index 31bbb8d..2ae6544 100644 --- a/config/webpack.config.js +++ b/config/webpack.config.js @@ -84,7 +84,7 @@ const commonOptions = { mode: "production", target: "web", resolve: { - extensions: [".ts", ".js"], + extensions: [".ts", ".js", ".html"], alias: { "@": global.SOURCE_DIR } @@ -97,6 +97,10 @@ const commonOptions = { options: { configFile: "config/tsconfig.json" } + }, + { + test: /\.html$/, + loader: path.resolve(CONFIG_DIR, "webpack/loader/to-string-loader.js") } ] }, diff --git a/config/webpack/loader/to-string-loader.js b/config/webpack/loader/to-string-loader.js new file mode 100644 index 0000000..cf26b28 --- /dev/null +++ b/config/webpack/loader/to-string-loader.js @@ -0,0 +1,41 @@ +module.exports = function(source) { + source = source + .replaceAll("\\", "\\\\") + .replaceAll("`","\\`") + .replaceAll("${", "\\${"); + + const replacements = {}; + let i = 0; + while (true) { + i = source.indexOf("$", i) + 1; + + if (i <= 0) { + break; + } + + const end = source.indexOf("$", i); + + if (end < 0) { + break; + } + + const replacementVariable = source.substring(i, end); + replacements[replacementVariable] = 1; + source = source.substring(0, i - 1) + `\${${replacementVariable}}` + source.substring(end + 1); + i = end + 1; + } + + source = `\`${source}\``; + + const replacementList = []; + + for (const replacement in replacements) { + replacementList.push(replacement); + } + + const replacementArguments = replacementList.length > 0 + ? `{ ${replacementList.join(", ")} }` + : ""; + + return `export default (${replacementArguments}) => ${source};`; +}; diff --git a/src/html.d.ts b/src/html.d.ts new file mode 100644 index 0000000..b913216 --- /dev/null +++ b/src/html.d.ts @@ -0,0 +1,3 @@ +declare module "*.html" { + export default (replacements: any) => string; +} diff --git a/src/scripts/functionality/view-khatian/download-information-pdf-page-content.html b/src/scripts/functionality/view-khatian/download-information-pdf-page-content.html new file mode 100644 index 0000000..e91c15e --- /dev/null +++ b/src/scripts/functionality/view-khatian/download-information-pdf-page-content.html @@ -0,0 +1,273 @@ +
+
-