Skip to content

Commit

Permalink
Cover image size inside table (#2669)
Browse files Browse the repository at this point in the history
* Fixed cover image size in measureImageWithDimensions.

* Add table example with image cell.

* add fit images example on table
  • Loading branch information
isamu authored Dec 21, 2023
1 parent 9175f83 commit 66696ad
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
70 changes: 69 additions & 1 deletion examples/tables.js
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,75 @@ 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: {
Expand Down
3 changes: 3 additions & 0 deletions src/DocMeasure.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ class DocMeasure {
let 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);
Expand Down

0 comments on commit 66696ad

Please sign in to comment.