【问题标题】:Send form data to a pdfkit iframe document将表单数据发送到 pdfkit iframe 文档
【发布时间】:2021-11-19 08:41:00
【问题描述】:

我想检索表单的值并将它们发送到后端生成的 pdfkit 文档。

目前,我只通过“获取”路线创建了一个简单的文档:

router.get(
  "/",
  authCheck,
  asyncHandler(async (req: express.Request, res: express.Response) => {
    const doc = new PDFDocument();
    let filename = "toto";
    filename = encodeURIComponent(filename) + ".pdf";
    res.setHeader(
      "Content-disposition",
      'attachment; filename="' + filename + '"'
    );
    res.setHeader("Content-type", "application/pdf");
    const content = "contenu";
    doc.y = 300;
    doc.text(content, 50, 50);
    doc.pipe(res);
    doc.end();
  })
);

这是检索创建的文档的代码:

<iframe className="preview-pdf__container" src={pdfContent} />

如何发送我的表单数据并将其返回到文档中?有 POST 吗?

【问题讨论】:

    标签: html node.js reactjs pdfkit


    【解决方案1】:

    这就是我如何将表单中的数据获取到服务器中,然后使用 node.js 将其导出到服务器中的不同文件(如果有帮助)。不过,我不完全确定如何将其从服务器中恢复到 iframe 中。

    HTML:

    <div class="wrapper">
            <form action="/login" method="POST">
                <label id="email-label">Email</label>
                <div class="textarea" id="email">
                    <input type="email" name="email" id="authentactor-email" value="" required>
                </div>
    
                <label>Password</label>
                <div class="textarea" id="password">
                    <input type="password" name="password" id="authentactor-password" value="" required>
                </div>
    
                <div id="button-wrapper">
                    <button type="submit" id="button">Login</button>
                </div>
            </form>
        </div>
    

    node.js

     //Allows you to Export form data from index.js
     app.post('/login');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-03
      • 2014-01-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多