How to take HTML form data as text and send them to html2pdf ?

In order to convert the HTML form data into pdf, the main approach is to use the html2pdf() function from the html2pdf library.
Approach: First, create a form with encryption type as text and add some input fields. After that, we need to use the html2pdf(element) function from the html2pdf library. Provide an onclick() functionality on the Submit button in the form. The html2pdf(element) function takes an input which is the id of the tag or form that needs to be converted to pdf format.
Example: This example shows the use of the above-explained approach.
HTML
| <!DOCTYPE html> <htmllang="en"> <head>     <metacharset="UTF-8">     <metaname="viewport"content=      "width=device-width,initial-scale=1.0">  Â    <!-- CSS only -->    <linkhref=         integrity= "sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1"        crossorigin="anonymous"rel="stylesheet">  Â    <!-- Html2Pdf  -->    <scriptsrc=         integrity= "sha512vDKWohFHe2vkVWXHp3tKvIxxXg0pJxeid5eo+UjdjME3DBFBn2F8yWOE0XmiFcFbXxrEOR1JriWEno5Ckpn15A=="        crossorigin="anonymous">     </script>  Â    <style>         .heading{           text-align: center;           color: #2F8D46;         }     </style> </head>  Â<body>     <h2class="heading">       GeeksForGeeks     </h2>  Â    <!-- Form encrypted as text -->    <formid="form-print"enctype="text/plain"          class="form-control">  Â        <labelfor="name">           <strong>Name: </strong>         </label>         <inputclass="form-control"type="text"          id="name"name="Name"placeholder="Enter Name">         <br>  Â        <labelfor="age">           <strong>Enter Age: </strong>         </label>         <inputclass="form-control"type="text"          id="age"name="Age"placeholder="Enter Age">         <br>  Â        <labelfor="subject">           <strong>Select Subject: </strong>         </label>         <selectclass="form-control"            id="subject"name="subject">             <optionvalue="Web">                 Web development             </option>             <optionvalue="App">                 App development             </option>             <optionvalue="Others">                 Others             </option>         </select>         <br>          Â        <labelfor="message">           <strong>Enter Message </strong>         </label>         <textareaclass= "form-control"          id="message"name="message"          placeholder="Enter you message"          style="height:100px">         </textarea>         <br>  Â        <inputtype="button"class="btn btn-primary"          onclick="GeneratePdf();"value="GeneratePdf">     </form>                   Â    <script>                   // Function to GeneratePdf         function GeneratePdf() {             var element = document.getElementById('form-print');             html2pdf(element);         }     </script>  Â    <scriptsrc=         integrity= "sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW"        crossorigin="anonymous">     </script> </body> </html> | 
Output:
 
take HTML form data as text and send them to html2pdf
 
The Pdf of the Html form
There is much functionality of the html2pdf library that you can explore in order to change the filename(of Pdf), its ratio, and much more. To explore more refer to the documentation of the html2pdf library.
 
				 
					


