Send Data by ajax library TCPDF

0

I need to send data from ajax to a pdf, but at the time of printing the data is lost, is there any configuration of TCPDF, so that it responds to ajax requests?

function ComprobanteCliente()
{

    $.post("<?= base_url() ?>PdfImprimirController/GeneraImpresionPDF/CHECKLIST CLIENTE", {
                'id_cliente':$('#hddndi').val()          
            });
}

TCPDF

At the time of writing the url

PdfImprimirController/GeneraImpresionPDF/ENTREGA%20DE%20VEHICULO

the pdf is executed, with the option "I" I print it without saving, what I can not do is to receive the variable ajax

$data['id_cliente']=$this->input->post('id_cliente');

and print at the same time thanks

$pdf->Output('example_001.pdf', 'I');

When sending the ajax request to the pdf the google chrome network generates a coding that does not interpret the browser

This is a fragment of the sample

%PDF-1.7
%âãÏÓ
16 0 obj
<< /Type /Page /Parent 1 0 R /LastModified (D:20170329202948+02'00') /Resources 2 0 R /MediaBox [0.000000 0.000000 595.276000 841.890000] /CropBox [0.000000 0.000000 595.276000 841.890000] /BleedBox [0.000000 0.000000 595.276000 841.890000] /TrimBox [0.000000 0.000000 595.276000 841.890000] /ArtBox [0.000000 0.000000 595.276000 841.890000] /Contents 17 0 R /Rotate 0 /Group << /Type /Group /S /Transparency /CS /DeviceRGB >> /PZ 1 >>
endobj
17 0 obj
<</Filter /FlateDecode /Length 1846>> stream
xí\ÛVÛ8Õs¾Bíî¶x£Ðë*m¡´/mWW&KB)ÓùªùµùÙm¢Ø!M88Y¶Étnû]bÎLÂñ¡ÓW8¾ÑO_pÙÅñÇ~ëÉm?ThÆÃîìѧ;->«mTÉÆ:$"±D¿¥
SFÛÔPÔÎnM¨ák­âtE¬.Aû=ºGÑçÝQ7}oì̽¹aå-­Ë¨1ÚZ¡%=¦\¤VN;G¨HKUZ]?¨å¾¿)í­ÖXAý¡ôZ­á¡ê¨%>Cïfyfº®·ÎZÒâT²Wb§
"ïÏVíuÐ<_)_«JeÒJg-¡ínЭEaÌüJ[[Yvj2ª][×=wO¢I4Óä]¢E   ',1ÜCæÎ.ýô<%oÈÙÆõ9Y#l 
    
asked by Javier Antonio Aguayo Aguilar 29.03.2017 в 20:24
source

2 answers

0
<object id="pdf" data="" type="application/pdf" width="100%" height="100%"></object>

<script>
// como te puedes dar cuenta, para pasar los datos usamos un arreglo
// para recuperar la respuesta agregamos un metodo llamado .done, y es ahi donde recuperamos el PDF.
$.post( "tu.php", {id_cliente:"123")
.done(function( data ) {
   //Aquí se debería regresar el contenido del PDF.
   ahora solo lo agregamos en el object.
   $( "#pdf" ).html( data );
});
</script>
    
answered by 29.03.2017 в 21:32
0

I have also tried everything and I can not from an ajax jquery post, but I have achieved it in the following way:

HTML Code:

<button type="button" onclick="imprimir();">Imprimir</button>

PHP Code: (file: actions.php) Generate the PDF with TCPDF

// Recibe parámetros mediante POST
if (isset($_POST['campo1'])) { $campo1 = $_POST['campo1']; }
if (isset($_POST['campo2'])) { $campo1 = $_POST['campo2']; }
// ... //Otras lineas de código que generan tu PDF.
// Muestra tu PDF sin guardar en disco, en el popup creado desde el javascript.
$pdf->Output('archivo.pdf', 'I');

JS Code:

function imprimir () {
  // pon AQUI tu codigo AJAX para otras acciones previas
  var mapForm = document.createElement("form");
  mapForm.target = "newFormWindow";
  mapForm.method = "POST";
  mapForm.action = "actions.php"; // PHP con código para mostrar el PDF
  // Crea los inputs
  var mapInput1 = document.createElement("input");
  var mapInput2 = document.createElement("input");
  mapInput1.type = "text";
  mapInput1.name = "campo1";
  mapInput1.value = "valor1";
  mapInput2.type = "text";
  mapInput2.name = "campo2";
  mapInput2.value = "valor2";
  mapForm.appendChild(mapInput1);
  mapForm.appendChild(mapInput2);
  document.body.appendChild(mapForm);
  // Adiciona form a dom
  document.body.appendChild(mapForm);
  // Abre nueva ventana popup (fullscreen) donde se mostrará la información
  window.open("", "newFormWindow", "height="+screen.height+",width="+screen.width+",resizable=yes");
  // submit form
  mapForm.submit();
  // pon AQUI tu codigo AJAX para otras acciones posteriores
}
    
answered by 17.08.2017 в 22:40