程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了TypeError: (0 , _htmlPdf.create)(...).foFile 不是函数大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决TypeError: (0 , _htmlPdf.create)(...).foFile 不是函数?

开发过程中遇到TypeError: (0 , _htmlPdf.create)(...).foFile 不是函数的问题如何解决?下面主要结合日常开发的经验,给出你关于TypeError: (0 , _htmlPdf.create)(...).foFile 不是函数的解决方法建议,希望对你解决TypeError: (0 , _htmlPdf.create)(...).foFile 不是函数有所启发或帮助;

我正在尝试使用“HTML-pdf”包在 nodeJs 中创建一个 pdf 文件。@H_450_3@

首先我导入为 import pdf from "HTML-pdf" 并收到此错误:
_htmlPdf.default.create(...).foFile is not a function.@H_450_3@

但是当我导入 import { create } from "HTML-pdf" 时,我在控制台中收到此错误:
TypeError: (0,_htmlPdf.create)(...).foFile is not a function@H_450_3@

这是我使用的模板在 nodeJs 中使用了 Babel Js):@H_450_3@

const labresult = (formData) => {
  const today = new Date();

  return `
    <!DOCTYPE HTML>
    <HTML lang="en">
      <head>
        <Meta charset="utf-8" />

        <title>LabResult</title>

        <style>
          body {
            BACkground: rgb(204,204,204);
          }
          page {
            BACkground: white;
            display: block;
            margin: 0 auto;
            /* border: 0.5rem outset black; */
            outline: 0.5rem solID black;
            /* outline: 0.8rem outset black; */
            outline-offset: -2rem;
            /* margin-bottom: 0.5cm;
            Box-shadow: 0 0 0.5cm rgba(0,0.5); */
          }
          page[size='A4'] {
            wIDth: 21cm;
            height: 29.7cm;
          }
          h1,h2,h3,h4 {
            Font-family: 'Nunito',sans-serif;
            Font-weight: bold;
            color: #388fe3;
          }

          h1 {
            Font-size: 2.7rem;
          }

          h2 {
            Font-size: 2.3rem;
          }

          h3 {
            Font-size: 2rem;
          }

          h4 {
            Font-size: 1.6rem;
            color: #000;
          }

          th,td {
            Font-family: 'Nunito',sans-serif;
          }

          p {
            Font-family: 'Open Sans',sans-serif;
          }

          .outer {
            display: table;
            position: absolute;
            top: 0;
            left: 0;
            height: 100%;
            wIDth: 100%;
          }

          .mIDdle {
            display: table-cell;
            vertical-align: mIDdle;
          }

          .inner {
            margin-left: auto;
            margin-right: auto;
            wIDth: 17cm;
            /* whatever wIDth you want */
          }
          table {
            wIDth: 100%;
            margin: 1.5rem 0;
            border-collapse: collapse;
            border: 1px solID #000;
          }
          td,th {
            border: 1px solID #000;
            padding: 0.5rem;
            Font-size: 1.15rem;
          }

          th {
            text-align: start;
          }
        </style>
      </head>
      <body>
        <page size="A4">
          <h2
            style="
              color: rgb(221,82,47);
              margin-top: 2cm;
              margin-left: 5cm;
              position: absolute;
              text-decoration: underline;
            "
          >
            Bahodir Shifo Diagnostika
          </h2>
          <p
            style="
              Font-weight: bold;
              color: rgb(40,214,98);
              Font-size: 2em;
              margin-left: 7cm;
              margin-top: 4cm;
              position: absolute;
            "
          >
            Диагностический центр
          </p>
          <div style="Font-weight: bold; margin-top: 4.6cm; position: absolute; margin-left: 6.5cm; color: #388fe3">
            <p>г. Ташкент,Яшнабадский р-н,ул. Aвиасозлар,дом 56</p>
            <p style="position: relative; margin-top: -0.3cm; margin-left: 0.5cm">
              +99890 983 05 72 +99890 372 54 18 (Telegram)
            </p>
          </div>
          <div style="Font-weight: bold; margin-top: 7cm; position: absolute; margin-left: 2cm; Font-size: larger">
            <p>Дата исследования:</p>
            <p>Пациент:</p>
            <p>Ден рождения:</p>
          </div>
          <div style="Font-weight: bold; margin-top: 7cm; position: absolute; margin-left: 10cm; Font-size: larger">
            <p>10.11.2021</p>
            <p>Jon snow</p>
            <p>11.12.1989</p>
          </div>
          <div style="Font-weight: bold; margin-top: 11cm; position: absolute; margin-left: 2cm; Font-size: larger">
            <table style="wIDth: 17cm;">
              <thead>
                <tr>
                  <th>Наименование</th>
                  <th>Резултат</th>
                  <th>Норма</th>
                  <th>Ед. изм.</th>
                </tr>
              </thead>
              <tbody>
                <tr>
                  <td></td>
                  <td></td>
                  <td></td>
                  <td></td>
                </tr>
              </tbody>
            </table>
          </div>
          <div style="Font-weight: bold; margin-top: 23cm; position: absolute; margin-left: 2cm; Font-size: larger">
            <p>Интерпретация резултатов анализов толко за лечашим врачом!</p>
            <p style="color: #388fe3; position: relative; margin-top: -0.5cm">"BAHODIR SHIFO" Желайет Вам здоровя</p>
            <p style="color: #388fe3">В случаи утери документа копия не выдаеця</p>
            <p style="Font-size: larger">Врач лаборант: Дехканова Г.М_______________</p>
          </div>
        </page>
      </body>
    </HTML>
  `;
};

export default labresult

路线如下:@H_450_3@

import labresult from '../../utils/labresult';

router.post('/create-pdf',requireJwtAuth,(req,res) => {
  create(labresult(),{}).fofile('labresult.pdf',(err) => {
    console.log('API Call to create-pdf');
    if (err) {
      return res.status(500).Json({ message: 'Failed to create pdf.' });
    }

    return res.status(200);
  });
});

解决方法

从'../../utils/labresult'导入实验室结果;@H_450_3@

router.post('/create-pdf',requireJwtAuth,(req,res) => {
  create(labresult(),{}).toFile('labresult.pdf',(err) => {
    console.log('API Call to create-pdf');
    if (err) {
      return res.status(500).json({ message: 'Failed to create pdf.' });
    }

    return res.status(200);
  });
});

大佬总结

以上是大佬教程为你收集整理的TypeError: (0 , _htmlPdf.create)(...).foFile 不是函数全部内容,希望文章能够帮你解决TypeError: (0 , _htmlPdf.create)(...).foFile 不是函数所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。