I want to generate a pdf with the FPDF library, I have a template with a button that when pressed makes an ajax query and I want it to return a new tab with the pdf generated by the library.
my template (task.tpl)
{extends file='page.tpl'} {block name='page_content_container'} <label id="random_number"></label> <section> <p><label>Introduce ancho:</label> <input type="text" id="name" name="name" maxlength="8" size="10" /></p> <p><label>Introduce alto:</label> <input type="text" id="name" name="name" maxlength="8" size="10" /></p> <form method="post"> <button id="plantilla" value="val_1" name="but1">button 1</button> <input id="access_token" type="hidden" name="access_token" value="<?php echo $_SESSION['access_token']; ?>" /> </form> </section> {/block}
my js file (multipurpose.js)
$(document).ready(function(){
$('#plantilla').click(function(){
$.ajax({
url:mp_ajax,
data:{
},
method: 'POST',
success: function(data) {
//$('#random_number').html(data)
},
error: function(result) {
alert('error');
}
});
});
})
my php file (ajax.php)
<?php require_once('../../config/config.inc.php'); require_once('../../init.php'); require('../../vendor/fpdf/fpdf.php'); include('../../vendor/fpdf/fpdf.php'); ob_start(); require('vendor/fpdf/fpdf.php'); $pdf = new FPDF('P','mm',array(20,10)); $pdf->AddPage(); $pdf->Output();