Skip to content
Related Articles

Related Articles

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

Improve Article
Save Article
Like Article
  • Last Updated : 08 Jan, 2021

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 html2pdf(element) function from 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.



<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content=
    <!-- CSS only -->
    <link href=
        crossorigin="anonymous" rel="stylesheet">
    <!-- Html2Pdf  -->
    <script src=
          text-align: center;
          color: #2F8D46;
    <h2 class="heading">
    <!-- Form encrypted as text -->
    <form id ="form-print" enctype="text/plain" 
        <label for="name">
          <strong>Name: </strong>
        <input class="form-control" type="text" 
          id="name" name="Name" placeholder="Enter Name">
        <label for="age">
          <strong>Enter Age: </strong>
        <input class="form-control" type="text" 
          id="age" name="Age" placeholder="Enter Age">
        <label for="subject">
          <strong>Select Subject: </strong>
        <select class="form-control" 
            id="subject" name="subject">
            <option value="Web">
                Web development
            <option value="App">
                App development
            <option value="Others">
        <label for="message">
          <strong>Enter Message </strong>
        <textarea class= "form-control"
          id="message" name="message" 
          placeholder="Enter you message" 
        <input type="button" class="btn btn-primary" 
          onclick="GeneratePdf();" value="GeneratePdf">
        // Function to GeneratePdf
        function GeneratePdf() {
            var element = document.getElementById('form-print');
    <script src=


HomePage(index Page)

The Pdf of the Html form

There is much functionality of 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 html2pdf library.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!