I'm using the pdfmake lib to construct a pdf in Javascript. I receive json data of the layout of the page and the text/images that need to be displayed. My issue is that for pdf to recognize that two or more text/images are next to each other on the page you have to construct the content like this:
content: [
{
alignment: 'justify',
columns: [
{
text: 'Lorem ipsum dolor ..'
},
{
text: 'Lorem ipsum dolor ..'
}
]
}]
For reference, see this link. (under Columns)
So in other words, I need to filter my layout for items that have the same y value, and construct a column with the text/image for each of these. I already have working code that uses the data I receive and constructs content, but can't seem to figure out how to filter the data for items that are next to each other.
The data I receive looks like this:
[
{
height: 8,
width: 12,
x: 0.
y: 1,
type: 'text',
text: 'Testing',
textType: 'heading1'
},
{
height: 6,
width: 12,
x: 0.
y: 2,
type: 'text',
text: 'Testing_again',
textType: 'paragraph'
},
{
height: 6,
width: 12,
x: 0.
y: 2,
type: 'text',
text: 'Testing_once_again',
textType: 'paragraph'
}
]
So in the above example, my finished content should look like this:
content: [
{
text: 'Testing'
},
{
alignment: 'justify',
columns: [
{
text: 'Testing_again'
},
{
text: 'Testing_once_again'
}
]
}]
In other words, all objects that have the same y value should be put in columns. Any help in accomplishing this would be greatly appreciated.
Note: This is my first post, so please let me know if I need to add something or explain anything in a better way. TIA