Click here to Skip to main content
15,879,474 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to generate and download pdf file using the library TCPDF of php. I pass the parameters to php thru ajax using javascript: These parameters comes from html table, that I transfer to the PHP as an array :Here is the portion of my Javascript code:
var myTableArray = [];
    var nb = 0;

$("table#Table tr").each(function() {
    var arrayOfThisRow = [];
    var tableData = $(this).find('td');
    if (tableData.length > 0) {
        tableData.each(function() { arrayOfThisRow.push($(this).text()); });
        myTableArray.push(arrayOfThisRow);
        nb = nb +1;
    }
});

    jQuery.ajax({  
         type: "post",  
         url: "Generate_PDF.php",  
         data: {table:myTableArray, Line :nb },
         success: function(count){  
             alert("done"); 
         }  
    }); 

And here is the PHP Code:
function fetch_data()  
 {
$aDataTableDetailHTML = ' ';
     $count = $_POST['Line'];
      $line = 0;
      $row = 0;
      for($line; $line < $count; $line++)
      {
          for ($row =0; $row < 2; $row++)
          {
             If ($row == 0)
                {
    $aDataTableDetailHTML .= '<tr><td>'.$_POST['table'][$line][$row].'</td>';
                } enter code here
                else
                {
    $aDataTableDetailHTML .= '<td>'.$_POST['table'][$line][$row].'</td></tr>'; 
                }
          }
      }
      $aDataTableDetailHTML1 = '<tr><td> introduction 123 </td><td> temps zero</td></tr>';
    return $aDataTableDetailHTML;


in the chrome consol ->Network->preiew I see that the pdf file does not get generated, and I see a strange long text that starts with:
%PDF-1.7
%âãÏÓ
7 0 obj
<< /Type /Page /Parent 1 0 R /LastModified (D:20170513141422+02'00') /Resources 2 0 R

This strange text is too long and it ends with:
0000006871 00000 n 
trailer
<< /Size 12 /Root 11 0 R /Info 9 0 R /ID [ <f7adf2ceab2607d2e2cecc277437d8cd> <f7adf2ceab2607d2e2cecc277437d8cd> ] >>
startxref
7080
%%EOF


Any Idea folks...!? Thanks

What I have tried:

I have Tried all I could...please see the explanation in my question, I feel free If you need any more clarifications.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900