【问题标题】:Variable with line break (\n) in PdfMakePdfMake 中带有换行符 (\n) 的变量
【发布时间】:2020-11-15 13:29:50
【问题描述】:

我正在尝试将包含换行符 (\n) 的变量传递给 PdfMake 中的表(在 Ionic 3 项目内),但生成的 PDF 不会将换行符视为新行。

table: {
        
        headerRows: 1,
        widths: ["80%", "20%"],

        body: [
          [
            { text: "Job Description", style: "center" },
            { text: "Total", style: "center" },
          ],
          [
            // JobDescriotiob is a string variable that contains \n character
            { text: JobDescription, style: "center" },
            { text: Price, style: "center" },
          ],
        ],
      },

结果是

但是,当我直接在文本中使用 (\n) 时效果很好

table: {
        
        headerRows: 1,
        widths: ["80%", "20%"],

        body: [
          [
            { text: "Job Description", style: "center" },
            { text: "Total", style: "center" },
          ],
          [
            { text: "test\nfff", style: "center" },
            { text: Price, style: "center" },
          ],
        ],
      },

结果是

有什么方法可以通过变量换行吗?

【问题讨论】:

    标签: typescript ionic3 pdfmake


    【解决方案1】:

    我通过将 jobdescription 中的任何字符替换为“\n”解决了这个问题

        JobDescription = JobDescription.split("--").join("\n");
    

    【讨论】:

    • “- -”作为分隔符是如何工作的?它是一种特殊的“拆分”语法吗?
    猜你喜欢
    • 2011-01-28
    • 1970-01-01
    • 2017-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    • 1970-01-01
    相关资源
    最近更新 更多