Coder Social home page Coder Social logo

sanumuhammedc / form-to-pdf Goto Github PK

View Code? Open in Web Editor NEW
8.0 1.0 0.0 108 KB

A simple form to pdf utility as per user input

Home Page: https://bit.ly/contact-card-maker

License: GNU General Public License v3.0

HTML 100.00%
html css javascript bootstrap jquery jspdf form pdf pdf-generation formtopdf

form-to-pdf's Introduction

Form-To-Pdf

A simple pdf generator using HTML and JavaScript

This is helpful for providing a certificate, bill or some sort of report for user as per their input

Here I have used a library called jspdf to make dynamic pdf and Bootstrap for styling the html page

Basic structure for Form to pdf

(use as a reference only)

<html>
  <head>
    <!--jspdf cdn -->
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.4/jspdf.min.js"></script>
  <!--Jquery cdn-->
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.js"></script>
  </head>
  <body>   
     <div>
         <!--create input field to get data in given format-->    
       <input type="text" id="name" value="" placeholder="Input Name here..."><br>
       <input type="text" id="email" value="" placeholder="Input email here..."/>
          <!--print button-->
        <buton type="button" id="button">Print</button>
     </div>


   <script>

         //function to add input from html form to image and print as document start here
         //function is called when generate button is clicked

         $('#button').click(function() {

         //creating a js pdf  
         var doc = new jsPDF();

         // Design form in JPEG format in any dimension here A4 size is used
         // Convert this image to base64 format using the site "https://www.base64-image.de/" 
         // copy the base64 image to below variable
         var imgData = '(paste base64 code here)';

          //Adding image to pdf here 0,0 represent the cordinate of image and 210,297 represent size(here it is A4 size)
          doc.addImage(imgData, 'JPEG', 0, 0, 210, 297);

          //Accessing values from form and assigning to variables
          var name = $('#name').val();
          var email = $('#email').val();

          //setting font size and color for input text 
          doc.setFontSize(26);
          doc.setTextColor(92, 76, 76);

          //putting the input values in specific positions of image/pdf by specifying co-ordinate
          doc.text(23, 81, name);
          doc.text(23, 122, email);

          //Saving pdf in required name
          doc.save('Contact Card.pdf');
          
          // (comment above line and use code below if you want to preview instead of directly printing)
          // var string = doc.output("datauristring");
          //     var embed = "<embed width='100%' height='100%' src='" + string + "'/>";
          //     var x = window.open();
          //     x.document.open();
          //     x.document.write(embed);
          //     x.document.close();

    });
    //function to add input from html form to image and print as document end here 
   </script>

 </body>

form-to-pdf's People

Contributors

sanumuhammedc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

form-to-pdf's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.