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. --- 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 + 6 files changed, 294 insertions(+), 242 deletions(-) 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 (limited to 'src') 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 @@ +
+ + +
$details$
+ + +
diff --git a/src/scripts/functionality/view-khatian/download-information-pdf-page-content.ts b/src/scripts/functionality/view-khatian/download-information-pdf-page-content.ts deleted file mode 100644 index 9ff18ec..0000000 --- a/src/scripts/functionality/view-khatian/download-information-pdf-page-content.ts +++ /dev/null @@ -1,219 +0,0 @@ -const sanghaFacilitationCentreBannerUrl = chrome.runtime.getURL("/assets/sangha-facilitation-centre-banner.jpg"); - -export default (isPlotInformation: boolean, details: string, { district, block, mouza }: { district: string, block: string, mouza: string }) => ` - - -
${details}
- - -`; diff --git a/src/scripts/functionality/view-khatian/index.ts b/src/scripts/functionality/view-khatian/index.ts index e29e8a4..38e500b 100644 --- a/src/scripts/functionality/view-khatian/index.ts +++ b/src/scripts/functionality/view-khatian/index.ts @@ -1,8 +1,10 @@ -import { downloadPDF } from "@/shared/download-pdf"; -import getDownloadInformationPDFPageContent from "@/scripts/functionality/view-khatian/download-information-pdf-page-content"; +import { generateWebPage } from "@/shared/generate-web-page"; +import getDownloadInformationPDFPageContent from "@/scripts/functionality/view-khatian/download-information-pdf-page-content.html"; declare function load(): void; +const sanghaFacilitationCentreBannerUrl = chrome.runtime.getURL("/assets/sangha-facilitation-centre-banner.jpg"); + document.addEventListener("DOMContentLoaded", () => { const proxiedPost = $.post; @@ -26,13 +28,14 @@ document.addEventListener("DOMContentLoaded", () => { let isPlotInformation: boolean | null = null; const downloadInformationPDF = () => { - let contentElement = document.getElementById(isPlotInformation ? "plotdetails" : "khdetails"); - const documentStringContent = getDownloadInformationPDFPageContent(!!isPlotInformation, contentElement!.innerHTML, { + generateWebPage(getDownloadInformationPDFPageContent({ + sanghaFacilitationCentreBannerUrl, + isPlotInformation: !!isPlotInformation, + details: document.getElementById(isPlotInformation ? "plotdetails" : "khdetails")!.innerHTML, district: getValueOfSelectElement("#lstDistrictCode1"), block: getValueOfSelectElement("#lstBlockCode1"), mouza: getValueOfSelectElement("#lstMouzaList") - }); - downloadPDF(`
${documentStringContent}
`); + })); }; $.post = function() { diff --git a/src/shared/download-pdf.ts b/src/shared/download-pdf.ts deleted file mode 100644 index bd8f815..0000000 --- a/src/shared/download-pdf.ts +++ /dev/null @@ -1,17 +0,0 @@ -export const downloadPDF = (content: string) => { - const tab = window.open("about:blank", "_blank"); - - if (tab) { - tab.document.write(content); - tab.document.close(); - tab.focus(); - Promise.all(Array.from(tab.document.images) - .filter(img => !img.complete) - .map(img => new Promise(resolve => { - img.onload = img.onerror = resolve; - }))).then(() => { - tab.print(); - tab.close(); - }); - } -}; diff --git a/src/shared/generate-web-page.ts b/src/shared/generate-web-page.ts new file mode 100644 index 0000000..d7de655 --- /dev/null +++ b/src/shared/generate-web-page.ts @@ -0,0 +1,9 @@ +export const generateWebPage = (content: string) => { + const tab = window.open("about:blank", "_blank"); + + if (tab) { + tab.document.write(content); + tab.document.close(); + tab.focus(); + } +}; -- cgit v1.2.3