3

I'm using pdfmake. I'm trying to figure out how to add image to the end of text line instead of the new line. For example:

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

Using this description pdfmake generates PDF where first line is 'Test text', and second contains image. I need that text and image would be in single line like 'Test text [image]'.

Has anyone done this before?

I would like to get some advice on how to do it. Thanks.

Sumit patel
  • 3,807
  • 9
  • 34
  • 61

2 Answers2

4

Use columns

var dd = {
  content: [
    {
      columns: [
        {
          width: 'auto',
          text: 'Test text'
        },
        {
          width: '*',
          image: 'sampleImage.jpg', 
          width: 24, 
          height: 24
        }
      ]
    }
  ]
}
Vedran Jukic
  • 841
  • 8
  • 14
1

If you want the image to be inline with your Multiline text you can use columns + stack

Example:

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: '*'
 }]
sevenupxz3
  • 11
  • 2