TCPDF does not generate PDF file under ajax call

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • HappyGuy
    New Member
    • May 2017
    • 1

    TCPDF does not generate PDF file under ajax call

    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:

    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:
    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:201705131414 22+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 [ <f7adf2ceab2607 d2e2cecc277437d 8cd> <f7adf2ceab2607 d2e2cecc277437d 8cd> ] >>
    startxref
    7080
    %%EOF
    =============== =============== =============== ==

    Any Idea folks...!? Thanks
    Last edited by Dormilich; May 15 '17, 07:24 AM. Reason: please use code tags.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    and I see a strange long text that starts with:
    that strange long text is your PDF file!

    Comment

    • chipsld
      New Member
      • Jun 2017
      • 2

      #3
      Originally posted by Dormilich
      that strange long text is your PDF file!
      Do you know why it doesnt display the pdf ?
      And if you know the name of that format ? if there is one.

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        Do you know why it doesnt display the pdf ?
        because console->Network->preview considers everything text.

        Comment

        • chipsld
          New Member
          • Jun 2017
          • 2

          #5
          Yeah i know but it should be generated in the browser ?

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            your server creates the PDF, not the browser.

            Comment

            Working...