hummusRecipe
hummusRecipe copied to clipboard
Text Columns and Tables?
John, how would you like to see text columns and its close cousin tables added to the package? I have working versions of both: The following depicts creating text columns. Here the layout defines the size of the area to disperse columns (width, height), the number of columns and the gap between the columns.
let x = 72;
let y = 52;
let id = 1;
recipe
.createPage('letter')
.text('Multiple columns with auto text fill using single "layout".',
x, y-20,{color:'red'})
.layout(id, x, y, 500, 200, {columns:3, gap: 10})
.text(lorem, x, y, {
layout:id,
textBox:{
textAlign: 'justify',
style:{width:.5}}})
.endPage()
.endPDF();
which produces the following:
The following is an example of using the table interface: (data and layout information is not presented, just calls to interfaces). The user has the ability to control what happens when there is more data than can presented in a table (overflow), for instance create a new page and continue emitting the table, or as in the example below, re-position the table to another place on the page.
let nextTable = 30;
const tblFull2 = (self, row) => {
nextTable += 170;
if (nextTable > 500) {
return true;
}
return {position: [nextTable,302]};
};
let x = 50;
let y = 52;
recipe
.createPage('letter')
.text('Table with alternating row properties', 230, 30, {color:'#000000'})
.table(x, y, contents, {
columns: columns,
header: {cell:{padding:[8,2,8,2], textAlign:'left'}},
border: {stroke:"#dddddd"},
row: {nth:'odd', cell:{style:{fill:"#dddddd"}}}
}
)
.text('Tables showing new position when "overflow" encountered.', 80, y+200, {color:'#000000'})
.text('Note data driven property (color) assignment', 130, y+220, {size:12, color:'#000000'} )
.table(x-20, y+250, people.sort(compare), {
columns: pcols,
border:true,
header:{cell:{textAlign:'left'}},
row:{size:10},
overflow: tblFull2,
order: "first_name,last_name"
})
.endPage()
.endPDF();
which produces the following:
wow this is an amazing feature!
This doesn't seems working while modifying existing PDF. Issue with layout()
method. This is what I found in your code.
this.layout('_table_', x, y, 0, 0, { columns: columns, reset: true });
function layout(id, x, y, width, height, options = {}) {
if (!width) {
width = this.page.mediaBox[2] - x - this._margin.right; //fails here
}
if (!height) {
height = this.page.mediaBox[3] - y - this._margin.bottom;
}
}