【问题标题】:How to create ExpressJS PDF Template 'if statements'如何创建 ExpressJS PDF 模板“if 语句”
【发布时间】:2022-01-09 02:50:15
【问题描述】:

有谁知道在创建 PDF 时如何使用 expressjs 在 PDF 模板中创建 if 语句?例如,在 pdf-index.ejs 模板文件中类似于以下 sn-p :

<body>
    <% if($src === 'invoice'){ %>

        <%- include('./pdf-invoice.ejs') %>

    <% } else if($src === 'contract'){ %>

        <%- include('./pdf-contract.ejs') %>

    <% } %>
</body>

注意:上述在创建 PDF 时不与 EJS 一起使用

【问题讨论】:

    标签: node.js express pdf pdf-generation


    【解决方案1】:

    我正在使用html-pdf npm 包从 html 生成 pdf

    const template = (params) =>{
    
    return(`
    
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title></title>
    </head>
    <body>
    You can use if statement this way ${
      if(params == "hello"){
        return "1"
      }
    }
    
    </body>
    </html>`
    }
    
    
    
    module.exports = template
    
    

    【讨论】:

    • 感谢您的建议。
    猜你喜欢
    • 2014-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-01
    • 2013-10-17
    • 1970-01-01
    • 1970-01-01
    • 2022-01-18
    相关资源
    最近更新 更多