I am new with Codeigniter and I need to generate a PDF with this library that I use frequently, I have doubts in the generation that I send by AJAX :
$.ajax({
url:"<?php echo site_url('lecturas_pdf/')?>",
type:"POST",
//dataType:"JSON",
success:function(data){
alert(data);
$('#lectura_pdf').src = data;
//alert(data[0]);
console.log(data);
window.open(
'data:application/pdf,'+encodeURIComponent(data),
'Batch Print',
'width=600,height=600,location=_newtab'
);
}
});
This is my controller:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
*
*/
class Lecturas extends Castor_Controller{
function __construct(){
parent::__construct();
$this->load->model('lectura');
}
public function index(){
//$this->load->view('lecturas/lecturas');
$this->load->model('barrio');
$data['barrio']=$this->barrio->findAll();
$data['view']='lecturas/lecturas';
$data['output']='';
$this->load->view('layouts_backend_lte_datatables/main', $data);
}
public function listar_clientes(){
$barrio_id = $this->input->post('barrio_id');
$mes_consumo = $this->input->post('mes_consumo');
$list = $this->lectura->medidor_barrio($barrio_id);
foreach ($list as $medidor) {
$consumo = $this->lectura->lectura_mes($medidor->id, $mes_consumo);
}
}
public function listar_clientes_data(){
$barrio_id = $this->input->post('barrio_id');
$mes_consumo = $this->input->post('mes_consumo');
$list = $this->lectura->get_mes_consumo($barrio_id, $mes_consumo);
$no=0;
$output = '<div class="table-responsive">';
$output .= '<table class="table table-bordered">';
$output .= '<tr>';
$output .= '<th width="5%">Ord</th>';
$output .= '<th width="36%">Nombre</th>';
$output .= '<th width="18%">Medidor</th>';
$output .= '<th width="18%">Lectura anterior</th>';
$output .= '<th width="18%">Lectura nueva</th>';
$output .= '<th width="50%">Est</th>';
$output .= '</tr>';
foreach ($list as $data) {
$no++;
$output .= '<tr>';
$output .= '<td>'.$no.'</td>';
$output .= '<td>'.$data->apellido.'</td>';
$output .= '<td>'.$data->codigo.'</td>';
$output .= '<td class="data" data-id2="'.$data->id.'" contenteditable></td>';
$output .= '<td class="lectura_actual" data-id3="'.$data->id.'" contenteditable></td>';
//$output .= '<td class="lectura_anterior" data-id2="'.$data->id.'" contenteditable>'.$data->lectura_anterior.'</td>';
//$output .= '<td class="lectura_actual" data-id3="'.$data->id.'" contenteditable>'.$data->lectura_actual.'</td>';
$output .= '<td></td>';
$output .= '</tr>';
}
$output .= '</table></div>';
echo $output;
}
}
?>
This is the exit:
%PDF-1.3
3 0 obj
<</Type /Page
/Parent 1 0 R
/Resources 2 0 R
/Contents 4 0 R>>
endobj
4 0 obj
<</Filter /FlateDecode /Length 558>>
stream
x�m�Kr�0��>����"��g��IS�l�8��U�Ngz�Ғ(�7Ґ>�!��Ì�T�w6/���H���,�[Lh��(��tW}T��jΟ�|�ݮ�:
�����5pU*�
Nͥ�e}4A���f�& C�@�W��[|����Bb��%c�9���خ%ᗑ��!�7�%9J�N�ȶ�o?�})�}�pA���9�ed�R����$"8dt���:o����� 6�Oզ�\��c*Nc�GF1U�HZ���?/���4J����Qd&��1!��tJ��Q�$n\�E��҄S�Smaa�6S��PJ��,�������M}>'m�j�~h=�[R�<�nc�'2�v��� �d�=�h���u�"�¾�3,.M��v�ΝG�C� �t03.�0�'�K�Z-�tC�}�"P�6�t�C����@��6{{�V�Q���WXkۼ'�{T�,�V����
_zd�^���Ëq��ן�t�G��=�i�0����T�.Ծ9j߅;�ڛ�ŗO�e:.w7���d�Л�;�(f��
endstream
endobj
1 0 obj
<</Type /Pages
/Kids [3 0 R ]
/Count 1
/MediaBox [0 0 595.28 841.89]
>>
endobj
5 0 obj
<</Filter /FlateDecode /Length 364>>
stream
x�]R�n�0��>��L�%�DI�8���~�%E*r�ﻻvҪHX�gvVk?/���Ῑ��']�[�x5
�3\z��P�}����PO���j�Jݍ^���x6/f�����������|���4}�z�����}���@�,ۖ-��˺E�u�^�,���<�
�Z_�K� IQ����Yd����C�K�_�%q�8>�!J"V!2&bGģ%r"H��D��\}2EL1n��h�j���e��"a*H����:��d��9c���[�X1~��"�3�g��Ñ�;O��<r_�)-�<%a�I9�