convert Html to pdf using javascript
There are many scenario when we need to generate PDF using JavaScript. It is possible to generate html to pdf using jquery and jsPDF library. It allows you to select the DOM elements that you would wish to publish to PDF.
Below is the Sample Code for generating PDF. Add libraries- JQuery and jsPDF
html xmlns="http://www.w3.org/1999/xhtml">
head runat="server">
title>title>
script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js">script>
script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.js">script>
script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.0.272/jspdf.debug.js">script>
style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
style>
head>
body>
form id="form1" runat="server">
table>
tbody>
tr>
th>Companyth>
th>Contactth>
th>Countryth>
tr>
tr>
td>HCLtd>
td>Maria Anderstd>
td>USAtd>
tr>
tr>
td>Conduenttd>
td>Francisco Changtd>
td>UKtd>
tr>
tr>
td>Wiprotd>
td>Roland Mendeltd>
td>Austriatd>
tr>
tr>
td>NIIT Technologies LTDtd>
td>Helen Bennetttd>
td>INDIAtd>
tr>
tr>
td>Laughing Bacchus Winecellarstd>
td>Yoshi Tannamuritd>
td>Canadatd>
tr>
tr>
td>Magazzini Alimentari Riunititd>
td>Giovanni Rovellitd>
td>Italytd>
tr>
tbody>
table>
form>
body>
script>
let doc = new jsPDF('p', 'pt', 'a4');
doc.addHTML(document.body, function () {
doc.save('html.pdf');
});
script>
html>
For more details about C# interview question you can use below site.
References | pdf js library
Tag | convert html page to pdf using jquery,convert webpage to pdf using javascript,export html page to pdf on user click using javascript,javascript Convert Html to pdf source code,convert html to pdf using jquery example,generate pdf using jquery,jspdf html to pdf,export div content to pdf using javascript
Want to Learn C#.net interview questions and answers visit below link.
- C# interview questions and answers
This post first appeared on Dot Net Tutorial For Beginners With Examples, please read the originial post: here