Exporting Table Data to Print and PDF in React JS

Posted by






Export Table Data in React JS

Export table data in React JS

Exporting table data in React JS is a common requirement for many applications. In this article, we will discuss how to export table data to print and PDF in a React JS application using HTML tags.

Print table data

To print table data in a React JS application, you can use the window.print() method provided by the browser. You can create a button in your React component that triggers the window.print() method when clicked. Below is an example of how to achieve this:

    
      <button onClick={() => window.print()}>Print Table</button>
    
  

Export table data to PDF

To export table data to PDF in a React JS application, you can use a library like jspdf. First, you need to install jspdf using npm:

    
      npm install jspdf
    
  

Then, you can create a button in your React component that triggers the export to PDF functionality using jspdf. Below is an example of how to achieve this:

    
      import jsPDF from 'jspdf';

      const exportToPDF = () => {
        const doc = new jsPDF();
        // Add table data to the PDF
        doc.text('Table data', 10, 10);
        doc.save('table.pdf');
      }

      <button onClick={exportToPDF}>Export to PDF</button>
    
  

Conclusion

Exporting table data to print and PDF in a React JS application can be achieved using simple HTML tags and JavaScript libraries. By following the examples provided in this article, you can easily add this functionality to your React JS application.


0 0 votes
Article Rating
8 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
md sujait
10 months ago

tnx bro 🥰🥰🥰

Nayan Bhalerao
10 months ago

Thank you so much, using this you can directly import anything you want to display in react inside the pdf
this is excellent exceellent ,,,excelent, i have displayed my dashboard page(which include map, cards, charts and tables ) inside the pdf, this is great, thank you

Muhammed Safvan
10 months ago

I deployed my website and tried to make a pdf with my iPhone. The app crashes and not generating pdf. But it is working fine while using in laptop.

Monika K
10 months ago

thank you so much Sir

Kevin León
10 months ago

thanks papi

Nilupaji_ITwala
10 months ago

This is not good approach. Using this technique pdf style will different on different browsers. Ctrl +p also working same

SPORTS STIMULANT
10 months ago

Sir mail Kiya hai dekh ligiye ap thora ,, pehele bhi bat hua hai apse ….

Billa Saheb
10 months ago

Excellent…. great …awesome