/g, '\n') || ''; const recommendations = pdfContent.querySelector('.recommendations p')?.textContent || ''; // Define PDF document structure const docDefinition = { content: [ { text: 'Greenwashing Detector Report', style: 'header' }, { text: '\n' }, { text: riskIndicator, style: 'riskIndicator' }, { text: '\n' }, { table: { headerRows: 1, widths: ['*', 'auto', 'auto', 'auto'], body: rows }, layout: { fillColor: function (rowIndex) { return (rowIndex % 2 === 0 && rowIndex > 0) ? '#f2f2f2' : null; }, hLineColor: '#ddd', vLineColor: '#ddd' } }, { text: '\n' }, { text: 'Discrepancies', style: 'subheader' }, { text: discrepancies, style: 'body' }, { text: '\n' }, { text: 'Recommendations', style: 'subheader' }, { text: recommendations, style: 'body' } ], styles: { header: { fontSize: 18, bold: true, alignment: 'center', color: '#333' }, subheader: { fontSize: 14, bold: true, color: '#333' }, riskIndicator: { fontSize: 12, bold: true, alignment: 'center', color: riskIndicator.includes('High') ? '#F44336' : riskIndicator.includes('Medium') ? '#FFC107' : '#4CAF50' }, tableHeader: { bold: true, fontSize: 12, color: 'white', fillColor: '#4CAF50' }, body: { fontSize: 10, color: '#333' } }, defaultStyle: { fontSize: 10, color: '#333' }, pageMargins: [40, 60, 40, 60] }; try { // Generate and download PDF pdfMake.createPdf(docDefinition).download('Greenwashing_Detector_Report.pdf'); } catch (err) { console.error('PDF generation failed:', err); alert('Failed to generate PDF. Please try again.'); } }; });
/g, '\n') || ''; const recommendations = pdfContent.querySelector('.recommendations p')?.textContent || ''; // Define PDF document structure const docDefinition = { content: [ { text: 'Greenwashing Detector Report', style: 'header' }, { text: '\n' }, { text: riskIndicator, style: 'riskIndicator' }, { text: '\n' }, { table: { headerRows: 1, widths: ['*', 'auto', 'auto', 'auto'], body: rows }, layout: { fillColor: function (rowIndex) { return (rowIndex % 2 === 0 && rowIndex > 0) ? '#f2f2f2' : null; }, hLineColor: '#ddd', vLineColor: '#ddd' } }, { text: '\n' }, { text: 'Discrepancies', style: 'subheader' }, { text: discrepancies, style: 'body' }, { text: '\n' }, { text: 'Recommendations', style: 'subheader' }, { text: recommendations, style: 'body' } ], styles: { header: { fontSize: 18, bold: true, alignment: 'center', color: '#333' }, subheader: { fontSize: 14, bold: true, color: '#333' }, riskIndicator: { fontSize: 12, bold: true, alignment: 'center', color: riskIndicator.includes('High') ? '#F44336' : riskIndicator.includes('Medium') ? '#FFC107' : '#4CAF50' }, tableHeader: { bold: true, fontSize: 12, color: 'white', fillColor: '#4CAF50' }, body: { fontSize: 10, color: '#333' } }, defaultStyle: { fontSize: 10, color: '#333' }, pageMargins: [40, 60, 40, 60] }; try { // Generate and download PDF pdfMake.createPdf(docDefinition).download('Greenwashing_Detector_Report.pdf'); } catch (err) { console.error('PDF generation failed:', err); alert('Failed to generate PDF. Please try again.'); } }; });