05-02-2024, 02:01 AM
I've been working on a project that requires the conversion of specific parts of an HTML page into a PDF document using JavaScript. The challenge I'm facing is that while I've been using jsPDF, it seems to only support adding text to a PDF, and not directly converting HTML. I'd appreciate some guidance on how I can capture the HTML content within a specific div and render it as it looks on the web page into a PDF document. Here is a snippet of the HTML I want to convert:
The goal is to select only the content within the div with the id "pdf" and have it rendered in the PDF. Additionally, I'd like the PDF to be automatically downloaded with the filename 'foobar.pdf'. If anyone has experience with converting HTML to PDF on the client side, please let me know how to achieve this.
Code:
<
!DOCTYPE html >
<
html >
<
body >
<
p > don 't print this to pdf</p> <
div id = "pdf" >
<
p > < font size = "3"
color = "red" > print this to pdf < /font></p >
<
/div> <
/body> <
/html>
The goal is to select only the content within the div with the id "pdf" and have it rendered in the PDF. Additionally, I'd like the PDF to be automatically downloaded with the filename 'foobar.pdf'. If anyone has experience with converting HTML to PDF on the client side, please let me know how to achieve this.