I'm needing to submit div content from one page to my html2pdf conversions page. I was wanting to do this using jquery so I don't have to leave my home page to make downloadable PDF file. I found an example online but I can't seem to make it work. Any help with this project would be appreciated greatly. Here's the code I found.
[CODE]
<!DOCTYPE>
<html>
<head>
<title>Nations and Flags</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script src="js/jquery-1.9.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#exportentry").click(function(e){
e.preventDefault();
if(submitted){
var data = $("#container").html();
var filename = "Entry_Report.pdf";
$.ajax({
type:"POST",
url: "test.php",
data: {data:data, filename:filename},
dataType: "json",
success: function(data) {
alert('success');
}
})
}else{
alert("No Report To Export");
}
});
});
</script>
</head>
<body>
<div id="container">
<center><h3>Nations and Flags</h3></center>
<table border="1" width="500" cellspacing="0" cellpadding="2" align="center">
<tr><td><%=Request.QueryString("v")%> India</td><td width="200"><img src="imag/in-t.jpg" width="48" height="32"></td></tr>
<tr><td><%=Request.QueryString("v2")%>Australia</td><td width="200"><img src="imag/as-t.jpg" width="48" height="32"></td></tr>
<tr><td>Canada</td><td width="200"><img src="imag/ca-t.jpg" width="48" height="32"></td></tr>
<tr><td>China</td><td width="200"><img src="imag/ch-t.jpg" width="48" height="32"></td></tr>
<tr><td>Germany</td><td width="200"><img src="imag/de-t.jpg" width="48" height="32"></td></tr>
<tr><td>France</td><td width="200"><img src="imag/fr-t.jpg" width="48" height="32"></td></tr>
<tr><td>United Kingdom</td><td width="200"><img src="imag/uk-t.jpg" width="48" height="32"></td></tr>
<tr><td>United States of America</td><td width="200"><img src="imag/us-t.jpg" width="48" height="32"></td></tr>
</table>
<table border="0" width="500" cellspacing="0" cellpadding="2" align="center">
<tr><td align="center"><a href="http://www.scriptarticle.com" target="_blank">http://www.scriptarticle.com</a></td></tr>
</table>
</div>
<form id="exportentry" method="post" action="home.php">
<input type="submit" value="Create PDF">
</form>
</body>
</html>
[/CODE]
convert.php
[CODE]
<?php
require('html2fpdf.php');
if(isset($_POST['data'])){
$urlcontents = $_POST['data'];
$filename = $_POST['filename'];
$date = $_POST['date'];
convert($urlcontents, $filename, $date);
}
function convert($contents, $name, $currdate){
$pdf=new HTML2FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10, "Entry Report");
$pdf->SetFont('Arial', '', 12);
$pdf->Cell(90,12,'- '. $currdate);
$contents = strip_tags($contents, '<html><body><meta><img><h2><h4><br><div><ul><li><span>');
$pdf->SetY(20);
$pdf->WriteHTML($contents );
$content = $pdf->Output('', true);
$file = fopen($filename, "w");
fwrite($file, $content);
fclose($file);
}
?>
[/CODE]
rev,:next'