diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/scripts/functionality/view-khatian.ts | 31 | ||||
| -rw-r--r-- | src/shared/download-pdf.ts | 22 | ||||
| -rw-r--r-- | src/types/html2pdf.js.d.ts | 1 |
3 files changed, 54 insertions, 0 deletions
diff --git a/src/scripts/functionality/view-khatian.ts b/src/scripts/functionality/view-khatian.ts index e1d3831..e81613b 100644 --- a/src/scripts/functionality/view-khatian.ts +++ b/src/scripts/functionality/view-khatian.ts @@ -1,8 +1,26 @@ +import { downloadPDF } from "@/shared/download-pdf"; + declare function loadKhatian(): void; document.addEventListener("DOMContentLoaded", () => { const proxiedPost = $.post; + const submitButtonElement = document.querySelector("#khbutton") as HTMLButtonElement; + const separatorElement = document.querySelector("#bodycover > div > form > hr:nth-child(2)") as HTMLElement; + const formElement = document.querySelector("#bodycover > div > form") as HTMLElement; + let downloadPDFButton: HTMLButtonElement | null = null; + + const submitButtonElementComputedStyles = window.getComputedStyle(submitButtonElement); + const styles = Array.from(submitButtonElementComputedStyles) + .reduce( + (str, property) => `${str}${property}:${submitButtonElementComputedStyles.getPropertyValue(property)};`, + "" + ); + + const downloadKhatianInformationPDF = () => { + downloadPDF(document.querySelector("html") as HTMLElement, "khatian-details.pdf"); + }; + $.post = function() { if (arguments[0].startsWith("khDetailsAction_LandInfo.action")) { const callback = arguments[2]; @@ -13,6 +31,19 @@ document.addEventListener("DOMContentLoaded", () => { if (tableElement) { tableElement.style.height = "auto"; tableElement.style.width = "100%"; + + if (!downloadPDFButton) { + downloadPDFButton = document.createElement("button"); + downloadPDFButton.innerHTML = "Download PDF"; + downloadPDFButton.style.cssText = styles; + downloadPDFButton.style.width = "auto"; + downloadPDFButton.addEventListener("click", downloadKhatianInformationPDF); + formElement.insertBefore(downloadPDFButton, separatorElement); + } + } else if (downloadPDFButton) { + downloadPDFButton.removeEventListener("click", downloadKhatianInformationPDF); + formElement.removeChild(downloadPDFButton); + downloadPDFButton = null; } } } diff --git a/src/shared/download-pdf.ts b/src/shared/download-pdf.ts new file mode 100644 index 0000000..a034e44 --- /dev/null +++ b/src/shared/download-pdf.ts @@ -0,0 +1,22 @@ +import html2pdf from "html2pdf.js"; + +export const downloadPDF = (element: HTMLElement, filename: string = "banglarbhumi.pdf") => { + html2pdf().set({ + margin: 0, + filename: filename, + image: { + type: "jpeg", + quality: 0.98 + }, + html2canvas: { + scale: 1 + }, + jsPDF: { + unit: "in", + format: "letter", + orientation: "portrait" + } + }) + .from(element) + .save(); +}; diff --git a/src/types/html2pdf.js.d.ts b/src/types/html2pdf.js.d.ts new file mode 100644 index 0000000..c9a972e --- /dev/null +++ b/src/types/html2pdf.js.d.ts @@ -0,0 +1 @@ +declare module "html2pdf.js"; |
