如何使用pdfmake在文本行的末尾添加图像?

时间:2016-08-29 08:20:37

标签: javascript node.js pdfmake

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

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

使用此说明pdfmake生成PDF,其中第一行是“测试文本”,第二行包含图像。 我需要文字和图片一致,如“测试文字[图片]'”。

以前有人这样做过吗?

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

2 个答案:

答案 0 :(得分:2)

使用列

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

答案 1 :(得分:0)

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

示例:

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: '*'
 }]
相关问题