diff --git a/examples/tables.js b/examples/tables.js index dad6da800..881d448ce 100644 --- a/examples/tables.js +++ b/examples/tables.js @@ -320,7 +320,7 @@ var docDefinition = { ['Sample value 1', 'Sample value 2', 'Sample value 3'] ] }, - }, + }, { text: '... using a custom styler and overriding it in the second row', margin: [0, 20, 0, 8] }, { style: 'tableOpacityExample', @@ -685,6 +685,74 @@ var docDefinition = { ], }, }, + { text: 'Image on table', pageBreak: 'before', style: 'subheader' }, + { + style: 'tableExample', + color: '#444', + table: { + widths: [200, 'auto', 'auto'], + headerRows: 2, + // keepWithHeaderRows: 1, + body: [ + [ + { + text: 'Header with Colspan = 3', + style: 'tableHeader', + colSpan: 3, + borderColor: ['#ff00ff', '#00ffff', '#ff00ff', '#00ffff'], + alignment: 'center', + }, + {}, + {}, + ], + [ + { + text: 'Header 1', + style: 'tableHeader', + alignment: 'center', + }, + { + text: 'Header 2', + style: 'tableHeader', + alignment: 'center', + }, + { + text: 'Header 3', + style: 'tableHeader', + alignment: 'center', + }, + ], + [ + { + image: 'fonts/sampleImage.jpg', + cover: { width: 100, height: 100 }, + }, + { + image: 'fonts/sampleImage.jpg', + cover: { width: 100, height: 100 }, + }, + { + image: 'fonts/sampleImage.jpg', + cover: { width: 100, height: 100 }, + }, + ], + [ + { + image: 'fonts/sampleImage.jpg', + fit: [100, 100], + }, + { + image: 'fonts/sampleImage.jpg', + fit: [100, 100], + }, + { + image: 'fonts/sampleImage.jpg', + fit: [100, 100], + }, + ], + ], + }, + }, ], styles: { header: { diff --git a/src/docMeasure.js b/src/docMeasure.js index 495521280..9b35bf3dc 100644 --- a/src/docMeasure.js +++ b/src/docMeasure.js @@ -164,6 +164,9 @@ DocMeasure.prototype.measureImageWithDimensions = function (node, dimensions) { var factor = (dimensions.width / dimensions.height > node.fit[0] / node.fit[1]) ? node.fit[0] / dimensions.width : node.fit[1] / dimensions.height; node._width = node._minWidth = node._maxWidth = dimensions.width * factor; node._height = dimensions.height * factor; + } else if (node.cover) { + node._width = node._minWidth = node._maxWidth = node.cover.width; + node._height = node._minHeight = node._maxHeight = node.cover.height; } else { node._width = node._minWidth = node._maxWidth = node.width || dimensions.width; node._height = node.height || (dimensions.height * node._width / dimensions.width);