Created
October 31, 2018 09:37
-
-
Save hzy916/f53af2e51a5cd383d2e181c4621e6901 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<title></title> | |
<style type="text/css"> | |
body | |
{ | |
font-family: Arial; | |
font-size: 10pt; | |
} | |
table | |
{ | |
border: 1px solid #ccc; | |
border-collapse: collapse; | |
} | |
table th | |
{ | |
background-color: #F7F7F7; | |
color: #333; | |
font-weight: bold; | |
} | |
table th, table td | |
{ | |
padding: 5px; | |
border: 1px solid #ccc; | |
} | |
</style> | |
</head> | |
<body> | |
<table id="tblCustomers" cellspacing="0" cellpadding="0"> | |
<tr> | |
<th>Customer Id</th> | |
<th>Name</th> | |
<th>Country</th> | |
</tr> | |
<tr> | |
<td>1</td> | |
<td>John Hammond</td> | |
<td>United States</td> | |
</tr> | |
<tr> | |
<td>2</td> | |
<td>Mudassar Khan</td> | |
<td>India</td> | |
</tr> | |
<tr> | |
<td>3</td> | |
<td>Suzanne Mathews</td> | |
<td>France</td> | |
</tr> | |
<tr> | |
<td>4</td> | |
<td>Robert Schidner</td> | |
<td>Russia</td> | |
</tr> | |
</table> | |
<br /> | |
<input type="button" id="btnExport" value="Export" /> | |
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> | |
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.22/pdfmake.min.js"></script> | |
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.min.js"></script> | |
<script type="text/javascript"> | |
$("body").on("click", "#btnExport", function () { | |
html2canvas($('#tblCustomers')[0], { | |
onrendered: function (canvas) { | |
var data = canvas.toDataURL(); | |
var docDefinition = { | |
content: [{ | |
image: data, | |
width: 500 | |
}] | |
}; | |
pdfMake.createPdf(docDefinition).download("Table.pdf"); | |
} | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using pdfmake.js and html2canvas to export PDF from HTML table