I have created a dsp page and I was getting the result in web browser but I need to download that same result as PDF file. In my flowservice I have selected output template as HTML and using this below code.
Review Report
function setColorBasedOnResult() {
var rows = document.querySelectorAll('table tr');
for (var i = 1; i < rows.length; i++) { // Start from 1 to skip the header row
var resultCell = rows[i].cells[1]; // Get the cell containing the result
if (resultCell.textContent.trim().toLowerCase() === 'false') {
resultCell.style.color = 'red';
}
}
}
// Call the function after the page has loaded
window.addEventListener('load', setColorBasedOnResult);
function goBack() {
window.history.back();
}
function downloadPDF() {
const pdfOptions = {
margin: 10, // Set the margin of the PDF
filename: 'review_report.pdf',
image: { type: 'jpeg', quality: 0.98 }, // Image quality (if images are present)
html2canvas: { scale: 2 }, // Scale factor for rendering
jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' } // PDF format and orientation
};
const element = document.querySelector('table'); // Select the table to convert
// Generate PDF using html2pdf
html2pdf()
.from(element)
.set(pdfOptions)
.outputPdf()
.then(pdf => {
const blob = new Blob([pdf], { type: 'application/pdf' });
const url = URL.createObjectURL(blob);
// Create a link to trigger the download
const a = document.createElement('a');
a.href = url;
a.download = 'review_report.pdf';
a.click();
});
}
</script>
looks like the code snippet was not formatted properly by the forum editor.
Additionally I am missing a “” start tag in your code snippet.
This makes it difficult to analyze the code for correctness.
You might want to check for the resulting HTML-code when this page is rendered to see if the table is formatted correctly behind the scenes.
When I understand you correctly, the page is displayed properly, but when trying to download the pdf, there is some data missing.
Can you provide some screenshots from the rendered page and the downloaded pdf for verification, please?