【问题标题】:carbone js usage with react jscarbone js 与 react js 的使用
【发布时间】:2020-05-01 02:06:40
【问题描述】:

我试图以这种方式将 Carbone js 与 react 项目一起使用

const carbone = require("carbone");
const fs = require("fs");
export default class Home extends Component {
  constructor(props) {
....

我的保存 PDF 按钮功能

onClick() {
    // Data to inject
    var data = {
      firstname: "John",
      lastname: "Doe",
    };

    // Generate a report using the sample template provided by carbone module
    // This LibreOffice template contains "Hello {d.firstname} {d.lastname} !"
    // Of course, you can create your own templates!
    carbone.render(
      "./node_modules/carbone/examples/simple.odt",
      data,
      function (err, result) {
        if (err) {
          return console.log(err);
        }
        // write the result
        fs.writeFileSync("result.pdf", result);
      }
    );
  }

然后我得到了这个错误

TypeError: Cannot read property 'split' of undefined

我只需要向用户发送一个他填写了法律文件表格的 pdf 文件 像这样flashlawyer app 非常感谢您的小建议

【问题讨论】:

    标签: javascript node.js reactjs pdf-generation


    【解决方案1】:

     简答

    你不能直接在你的 React 应用中使用 Carbone,你需要一个安装了 Carbone 的服务器并使用 HTTP API。

    好的,那么现在?

    如果您不想构建自己的 Carbone 服务器,可以使用官方的,您可以阅读in the documentation。该服务有一个免费计划(每月 100 次渲染),并且有很大的支持。如果您需要帮助,请随时联系 Carbone 团队,他们是好人 :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-27
      • 1970-01-01
      • 2020-01-21
      • 2015-11-16
      • 1970-01-01
      • 2021-04-14
      相关资源
      最近更新 更多