I have a button that must generate a pdf file of a table already filtered. I handle the click action with JavaScript here's the code.
$('#Exportar').on('click', function(){
var oTable = $("#example").dataTable();
var data = oTable._('tr', {"filter":"applied"});
var ajaxurl = 'Exportar.php';
$.ajax({ url: ajaxurl,
data: {datosTabla: 'data'},
type: 'post',
success: function(output) {
// alert(output);
}
});
})
My PHP file (Exportar.php) looks like this:
<?php
require('/fpdf/fpdf.php');
if(isset($_POST['datosTabla']) && !empty($_POST['datosTabla'])) {
$action = $_POST['datosTabla'];
$pdf = new FPDF();
$pdf ->AddPage();
$pdf ->SetFont('Arial','',10);
$pdf ->Image('images/pdf_hover.png', 10, 10, 10, 10, 'png');
$pdf->Cell(18,10,'',0);
$pdf->Cell(150,10,'PDF exportado',1);
$pdf ->SetFont('Arial','',9);
$pdf->Cell(50,10,'Fecha: '.date('dd.-mm-Y'),'',0);
$pdf->Ln(15);
$pdf ->SetFont('Arial','B',11);
$pdf->Cell(70, 8,'',0);
$pdf->Cell(100, 8,'Reporte de Carteras',0);
$pdf->Ln(23);
$pdf ->SetFont('Arial','B',8);
$pdf->Cell(15, 8,'columna1',0);
$pdf->Cell(15, 8,'columna2',0);
$pdf->Cell(15, 8,'columna3',0);
$pdf ->SetFont('Arial','',11);
$pdf->Output();
}
?>
I have examine the post with the dev tools from Chrome and the post it's been done correctly. I just do not know why it's not working. I have tested the functionality with a simple alert on the client side and works perfectly fine(comes out from the success handler).
My FPDF folder its at the same level as Exportar.php file. Can anyone lend me a hand on this? I have already tried checking other ppl posts and the faq from FPDF but it hasn't been much of a help.
On the other hand I have tried the example file that comes with FPDF and when I click the demo link the PDF is not been generated. I don't know why is this.
Thanks in advance for your help.