Click here to Skip to main content
15,561,246 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I am using tcpdf php library to generate pdf documents. I need to specify an html element in the page to generate pdf document using jQuery and ajax. Here is ajax_test.php code:
$pdf = new TCPDF();
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
$pdf->AddPage();
//$pdf->Cell(190, 10, 'Hello world!', 1, 1, 'C');
$pdf->Output();

Now this is table.php code:
<h2>HTML Table</h2>
<p>Hello world!</p>
<table>
  <tr>
    <th>Company</th>
    <th>Contact</th>
    <th>Country</th>
  </tr>
  <tr>
    <td>Alfreds Futterkiste</td>
    <td>Maria Anders</td>
    <td>Germany</td>
  </tr>
  <tr>
    <td>Centro comercial Moctezuma</td>
    <td>Francisco Chang</td>
    <td>Mexico</td>
  </tr>
  <tr>
    <td>Ernst Handel</td>
    <td>Roland Mendel</td>
    <td>Austria</td>
  </tr>
  <tr>
    <td>Island Trading</td>
    <td>Helen Bennett</td>
    <td>UK</td>
  </tr>
  <tr>
    <td>Laughing Bacchus Winecellars</td>
    <td>Yoshi Tannamuri</td>
    <td>Canada</td>
  </tr>
  <tr>
    <td>Magazzini Alimentari Riuniti</td>
    <td>Giovanni Rovelli</td>
    <td>Italy</td>
  </tr>
</table>
<button>PDF</button>

I need when I press the pdf button download ONLY the table without refreshing the page using jQuery and ajax.

What I have tried:

How can I do this? Is there a way of doing this?
Posted
Updated 6-Sep-22 19:58pm

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