I have use the following type of code in the google appscript for downloading the html table as .pdf format but after update the Firefox browser the file unable to downlo… (baca lebih lanjut)
I have use the following type of code in the google appscript for downloading the html table as .pdf format but after update the Firefox browser the file unable to download but everything runs properly and the success message is appearing but the file is not downloading. Before, update the browser, the file was downloaded properly, please tell me how to resolve the problem. It's an URGENT. Please take necessary action at an earlier.
function exportToPDF() {
try {
const table = document.getElementById("dataTable");
if (!table || table.classList.contains('hidden')) {
showAlert("Nothing found to generate PDF!");
return;
}
const originalScrollPosition = {
body: document.body.scrollTop || document.documentElement.scrollTop
};
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
const tableContainer = document.querySelector(".table-container");
const cloneContainer = tableContainer.cloneNode(true);
cloneContainer.style.overflow = "visible";
cloneContainer.style.maxHeight = "unset";
cloneContainer.classList.add("no-scrollbar");
const clone = cloneContainer.querySelector("table");
clone.style.fontSize = "12px";
clone.style.borderCollapse = "collapse";
clone.style.width = "100%";
clone.querySelectorAll('th').forEach(th => {
th.style.fontSize = "10.5px";
th.style.padding = "1px";
th.style.border = "1px solid black";
});
clone.querySelectorAll('td').forEach(td => {
td.style.fontSize = "10.5px";
td.style.padding = "1px";
td.style.border = "1px solid black";
});
const now = new Date();
const dateTime = now.toLocaleString("en-GB", {
day: "2-digit", month: "2-digit", year: "numeric",
hour: "2-digit", minute: "2-digit", second: "2-digit",
hour12: true
});
const selectedYearValue = document.getElementById('yearSelect').value;
const wrapper = document.createElement("div");
wrapper.style.fontSize = "16px";
wrapper.style.fontFamily = "Arial, sans-serif";
wrapper.style.width = "100%";
const header = document.createElement("div");
header.style.textAlign = "center";
header.innerHTML = `
Financial Year wise Report on BEUP || 17th Assembly (2021-2026)
Financial Year: ${selectedYearValue}
Report as on: ${dateTime}
`;
wrapper.appendChild(header);
wrapper.appendChild(cloneContainer);
cloneContainer.style.marginTop = "2px";
cloneContainer.style.paddingTop = "0px";
const fileName = `MLA_wise_&_F-Y_wise_Report_as_on_${formatDateTimeForFilename()}.pdf`;
document.body.style.overflow = 'hidden';
const opt = {
margin: [5, 5, 5, 5],
filename: fileName,
image: { type: 'jpeg', quality: 1 },
html2canvas: {
scale: 2,
useCORS: true,
scrollY: 0,
windowHeight: document.documentElement.scrollHeight
},
jsPDF: {
unit: 'mm',
format: 'a4',
orientation: 'landscape'
}
};
html2pdf().set(opt).from(wrapper).save().then(() => {
document.body.scrollTop = originalScrollPosition.body;
document.documentElement.scrollTop = originalScrollPosition.body;
document.body.style.overflow = ;
showAlert("PDF file downloaded successfully!", 'success');
});
} catch (e) {
console.error("Error generating PDF:", e);
document.body.style.overflow = ;
showAlert("PDF generation failed. Check console for details.", 'error');
}
}