Help PDF Method (can search but has no styling)
Sat Aug 03 2024 11:59:36 GMT+0000 (Coordinated Universal Time)
Saved by
@iamkatmakhafola
// Method to export help content to PDF
exportToPDF(): void {
const doc = new jsPDF();
let y = 10;
const pageHeight = doc.internal.pageSize.height;
const margin = 10;
this.helpContent.forEach(item => {
if (y + 10 > pageHeight - margin) {
doc.addPage();
y = margin;
}
doc.setFontSize(14);
doc.text(item.title, margin, y);
y += 10;
doc.setFontSize(12);
const plainText = this.htmlToPlainText(item.content);
const splitContent = doc.splitTextToSize(plainText, 180 - 2 * margin);
splitContent.forEach((line: string) => {
if (y + 7 > pageHeight - margin) {
doc.addPage();
y = margin;
}
doc.text(line, margin, y);
y += 5;
});
y += 7; // Add space between sections
});
doc.save('help-guide.pdf');
}
// Method to convert HTML content to plain text
htmlToPlainText(html: string): string {
const doc = new DOMParser().parseFromString(html, 'text/html');
return doc.body.textContent || '';
}
content_copyCOPY
Comments