I had created a button. If i click the button it should automatically download a pdf.
I used fpdf to make the pdf but somehow it just show me some error with encrypted result.
Below is my code
display_table.php
<html>
<head>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.12.2.min.js"></script>
<script src="display_table.js"></script>
</head>
<body>
<input type="button" name="download_pdf" id="download_pdf" value="Download pdf here" onclick="download_pdf()">
</body>
</html>
display_table.js
function download_pdf() {
$.ajax({
type: "POST",
url: "http://localhost/fpdf/display_table_controller.php",
data: { download : "download"},
error: function(jqXHR, textStatus, errorThrown) {
alert(errorThrown);
},
success: function(data)
{
alert(data);
}
});
}
display_table_controller.php
<?php
include("fpdf.php");
include("courier.php");
include("helveticab.php");
$pdf_name = "test.pdf";
$pdf = new FPDF('P','mm','A4');
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output($pdf_name, "D");
?>
Can someone tell me what wrong here? thanks