Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Aymkdn committed Jun 21, 2022
1 parent 4645401 commit aff6b23
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 23 deletions.
2 changes: 1 addition & 1 deletion browser.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/browser-2.4.3.js

Large diffs are not rendered by default.

Binary file modified example.pdf
Binary file not shown.
8 changes: 5 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ function htmlToPdfMake(htmlText, options) {
var cellsHeights = [];
var tableWidths = [];
var tableHeights = [];
// determine if we have "width:100%" on the TABLE
var fullWidth = (element.getAttribute("width") === "100%" || (element.getAttribute("style")||"").replace(/width\s*:\s*100%/, "width:100%").includes("width:100%"));

ret.table.body.forEach(function(row, rowIndex) {
cellsWidths.push([]);
Expand Down Expand Up @@ -298,7 +300,7 @@ function htmlToPdfMake(htmlText, options) {
if (tableWidths.length > 0) {
// if all columns are in 'auto' and if we have 'width:"100%"' for the table
// then put widths:['*', '*' …], for all columns
if (ret.table.width === "100%" && tableWidths.filter(function(w) { return w==='auto' }).length === tableWidths.length) tableWidths=tableWidths.map(function() { return '*' });
if (fullWidth && tableWidths.filter(function(w) { return w==='auto' }).length === tableWidths.length) tableWidths=tableWidths.map(function() { return '*' });
ret.table.widths = tableWidths;
}
if (tableHeights.length > 0) ret.table.heights = tableHeights;
Expand Down Expand Up @@ -629,10 +631,10 @@ function htmlToPdfMake(htmlText, options) {
var width = element.getAttribute("width");
var height = element.getAttribute("height");
if (width) {
style.unshift("width:" + width + (isNaN(width) ? "" : "px"));
style.unshift("width:" + this.convertToUnit(width + (isNaN(width) ? "" : "px")));
}
if (height) {
style.unshift("height:" + height + (isNaN(height) ? "" : "px"));
style.unshift("height:" + this.convertToUnit(height + (isNaN(height) ? "" : "px")));
}
var styleDefs = style.map(function(style) { return style.toLowerCase().split(':') });
var ret = [];
Expand Down
24 changes: 6 additions & 18 deletions test/unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,9 @@ test("table (rowspan/colspan)", function(t) {
</tr>
<tr>
<td>Cell A1</td>
<td rowspan="2">
Cell B1 & B2
</td>
<td rowspan="2">Cell B1 & B2</td>
<td>Cell C1</td>
<td rowspan="2">
Cell D1 & D2
</td>
<td rowspan="2">Cell D1 & D2</td>
</tr>
<tr>
<td>Cell A2</td>
Expand All @@ -363,9 +359,7 @@ test("table (rowspan/colspan)", function(t) {
<td>Cell D3</td>
</tr>
<tr>
<td rowspan="2" colspan="3">
Cell A4 & A5 & B4 & B5 & C4 & C5
</td>
<td rowspan="2" colspan="3">Cell A4 & A5 & B4 & B5 & C4 & C5</td>
<td>Cell D4</td>
</tr>
<tr>
Expand Down Expand Up @@ -429,13 +423,9 @@ test("table (rowspan/colspan) with thead tbody", function(t) {
<tbody>
<tr>
<td>Cell A1</td>
<td rowspan="2">
Cell B1 & B2
</td>
<td rowspan="2">Cell B1 & B2</td>
<td>Cell C1</td>
<td rowspan="2">
Cell D1 & D2
</td>
<td rowspan="2">Cell D1 & D2</td>
</tr>
<tr>
<td>Cell A2</td>
Expand All @@ -447,9 +437,7 @@ test("table (rowspan/colspan) with thead tbody", function(t) {
<td>Cell D3</td>
</tr>
<tr>
<td rowspan="2" colspan="3">
Cell A4 & A5 & B4 & B5 & C4 & C5
</td>
<td rowspan="2" colspan="3">Cell A4 & A5 & B4 & B5 & C4 & C5</td>
<td>Cell D4</td>
</tr>
<tr>
Expand Down

0 comments on commit aff6b23

Please sign in to comment.