如何创建 ExpressJS PDF 模板'if statements'



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

<body>
<% if($src === 'invoice'){ %>
<%- include('./pdf-invoice.ejs') %>
<% } else if($src === 'contract'){ %>
<%- include('./pdf-contract.ejs') %>
<% } %>
</body>

注意:创建PDF 时,上述不适用于EJS

我使用html-pdfnpm包从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

最新更新