首页信息安全在React-Table中导出为PDF

在React-Table中导出为PDF

admin 12-07 13:12 144次浏览

我在react-table中有10行值。我需要转换为PDF格式吗?.ss是否可以转换?

1> lomse..:

使用jsPDF和jspdf-autotable完成此任务。查看以下代码:

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 (
      
this.exportPDF()}>Generate Report
); } } export default App;

这将生成如下所示的PDF:

希望这可以帮助。

在React-Table中导出为PDF
澳门十组三中三必中一组_2022年澳门今晚开奖结果历史 澳门三肖三码必中一期_2022年澳门马会传真论坛
相关内容