【问题标题】:How to add image at the end of text line using pdfmake?如何使用 pdfmake 在文本行末尾添加图像?
【发布时间】:2016-08-29 08:20:37
【问题描述】:

我正在使用pdfmake。我试图弄清楚如何将图像添加到文本行的末尾而不是新行。 例如:

var dd = {
    content: [
        'Test text',
        {image: 'sampleImage.jpg', width: 24, height: 24}
    ]
}

使用此描述 pdfmake 生成 PDF,其中第一行是“测试文本”,第二行包含图像。 我需要文本和图像像“测试文本 [图像]”一样在单行中。

以前有人做过吗?

我想就如何做到这一点获得一些建议。谢谢。

【问题讨论】:

    标签: javascript node.js pdfmake


    【解决方案1】:

    使用列

    var dd = {
      content: [
        {
          columns: [
            {
              width: 'auto',
              text: 'Test text'
            },
            {
              width: '*',
              image: 'sampleImage.jpg', 
              width: 24, 
              height: 24
            }
          ]
        }
      ]
    }
    

    【讨论】:

    • 谢谢,但它部分解决了这个问题。如果文本很长并且包含在多行中,那么提供的解决方案就不能很好地工作。
    【解决方案2】:

    如果您希望图像与您的多行文本内联,您可以使用列 + 堆栈

    例子:

    columns: [
     {
            image: "URL",
            height: 150,
            width: 180
     },
    
    {
        stack: [
        {
            columns: [
              {
                  text: 'First column first line',
                  width: '35%'
              },
    
              {
                   text: 'Second column first line',
                   width: '35%'
              },
    
              {
                   text: 'Third column first line',
                   width: '30%'
              }
            ]
        },
    
        {
             columns: [
              {
                   text: 'First column second line',
                   width: '35%'
              },
    
              {
                   text: 'Second column second line',
                   width: '35%'
              },
    
              {
                   text: 'Third column second line',
                   width: '30%'
              }
            ]
        }
        ],
            width: '*'
     }]
    

    【讨论】:

      猜你喜欢
      • 2022-06-24
      • 2013-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-08
      • 2022-06-11
      • 2021-10-02
      • 1970-01-01
      相关资源
      最近更新 更多