Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

React to pdf

const ref = React.createRef();

<div>
    <ReactToPdf targetRef={ref} filename="div-blue.pdf">
        {({toPdf}) => (
            <button onClick={toPdf}>Generate pdf</button>
        )}
    </ReactToPdf>
    <div style={{width: 500, height: 500, background: 'blue'}} ref={ref}/>
</div>
Comment

react convert table to pdf

import React from 'react';
import jsPDF from "jspdf";
import "jspdf-autotable";
import './App.css';

class App extends React.Component {

  constructor() {
    super();
    this.state = {
      people: [
        { name: "Keanu Reeves", profession: "Actor" },
        { name: "Lionel Messi", profession: "Football Player" },
        { name: "Cristiano Ronaldo", profession: "Football Player" },
        { name: "Jack Nicklaus", profession: "Golf Player" },
      ]
    }
  }

  exportPDF = () => {
    const unit = "pt";
    const size = "A4"; // Use A1, A2, A3 or A4
    const orientation = "portrait"; // portrait or landscape

    const marginLeft = 40;
    const doc = new jsPDF(orientation, unit, size);

    doc.setFontSize(15);

    const title = "My Awesome Report";
    const headers = [["NAME", "PROFESSION"]];

    const data = this.state.people.map(elt=> [elt.name, elt.profession]);

    let content = {
      startY: 50,
      head: headers,
      body: data
    };

    doc.text(title, marginLeft, 40);
    doc.autoTable(content);
    doc.save("report.pdf")
  }

  render() {
    return (
      <div>
        <button onClick={() => this.exportPDF()}>Generate Report</button>
      </div>
    );
  }
}

export default App;
Comment

PREVIOUS NEXT
Code Example
Javascript :: add two empty arrays javascript 
Javascript :: promise 
Javascript :: Use jsx extension react-native 
Javascript :: max string size javascript 
Javascript :: routerlink not working 
Javascript :: get props from methods in vue 
Javascript :: how to get form value 
Javascript :: mongoose express js post 
Javascript :: react native layout 
Javascript :: jquery check valid link 
Javascript :: sequelize transaction 
Javascript :: javascript math.ceil 
Javascript :: nodejs cache data 
Javascript :: axios 400 bad request 
Javascript :: react map array 
Javascript :: row auto textarea 
Javascript :: display json data in html table react 
Javascript :: react array if id is present do not add element 
Javascript :: polymorphism javascript 
Javascript :: Simplest Promise Example 
Javascript :: sequelize migration enum 
Javascript :: scroll to a section on click on sticky navbar menu html css js 
Javascript :: how to check if an element is in array javascript 
Javascript :: is javascript object oriented 
Javascript :: array class javascript 
Javascript :: window parent frame 
Javascript :: javascript weakset 
Javascript :: module imports as default 
Javascript :: set default value in dropdown angular 7 
Javascript :: javascript object/function which you want to proxy 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =