Created
June 30, 2020 07:43
-
-
Save mortalis13/06620d49963117faad91ffea9e92eaec 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> | |
<html> | |
<head> | |
<title></title> | |
<script src="https://unpkg.com/jspdf@latest/dist/jspdf.min.js"></script> | |
<script src="https://unpkg.com/jspdf-autotable"></script> | |
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script> | |
<script> | |
$(function(){ | |
function genPdf() { | |
var doc = new jsPDF(); | |
var img = $('#header')[0]; | |
doc.addImage(img, 'PNG', 16, 15, 178, 26); | |
doc.setFontSize(22); | |
doc.text('Title', 105, 56, {align:'center'}); | |
doc.setFontSize(16); | |
doc.text('Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod\ | |
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,\ | |
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo\ | |
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse\ | |
cillum dolore eu fugiat nulla pariatur.', 20, 67, {align:'left', maxWidth: 170}); | |
doc.autoTable({ | |
html: '.data table', | |
useCss: true, | |
margin: { top: 110 }, | |
}) | |
doc.setTextColor('#666666'); | |
doc.text('Footer', 105, 185, {align:'center'}); | |
doc.setTextColor('#333333'); | |
doc.save('data.pdf'); | |
} | |
$("#dwn").click(function(){ | |
genPdf(); | |
}); | |
}) | |
</script> | |
<style> | |
table{ | |
width:500px; | |
border-collapse:collapse; | |
font-size:1.1em; | |
font-family:"trebuchet ms"; | |
} | |
th{ | |
background: #d1e9b4; | |
} | |
td,th{ | |
border:1px solid #666; | |
width:250px; | |
padding:10px; | |
} | |
button { | |
border: 1px solid #aaa; | |
background: #eee; | |
padding: 16px 24px; | |
font-size: 16px; | |
margin: 8px 0; | |
} | |
button:hover { | |
cursor: pointer; | |
background: #e0e0e0; | |
} | |
</style> | |
</head> | |
<body> | |
<div> | |
<div><img id="header" src="header.png" alt=""></div> | |
<div>line1</div> | |
<div>line2</div> | |
<div>line3</div> | |
<div class="data"> | |
<table> | |
<tr> | |
<th>A</th> | |
<th>B</th> | |
<th>C</th> | |
<th>D</th> | |
</tr> | |
<tr> | |
<td>1</td> | |
<td>City1</td> | |
<td>Address1</td> | |
<td>Phone1</td> | |
</tr> | |
<tr> | |
<td>2</td> | |
<td>City2</td> | |
<td>Address2</td> | |
<td>Phone2</td> | |
</tr> | |
<tr> | |
<td>3</td> | |
<td>City3</td> | |
<td>Address3</td> | |
<td>Phone3</td> | |
</tr> | |
<tr> | |
<td>4</td> | |
<td>City4</td> | |
<td>Address4</td> | |
<td>Phone4</td> | |
</tr> | |
<tr> | |
<td>5</td> | |
<td>City5</td> | |
<td>Address5</td> | |
<td>Phone5</td> | |
</tr> | |
</table> | |
</div> | |
</div> | |
<button id="dwn" autofocus>Download</button> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment