diff --git a/src/elementWriter.js b/src/elementWriter.js index 9b176bcf1..f29cb59f6 100644 --- a/src/elementWriter.js +++ b/src/elementWriter.js @@ -261,10 +261,21 @@ ElementWriter.prototype.addFragment = function (block, useBlockXOffset, useBlock var v = pack(item.item); offsetVector(v, useBlockXOffset ? (block.xOffset || 0) : ctx.x, useBlockYOffset ? (block.yOffset || 0) : ctx.y); - page.items.push({ - type: 'vector', - item: v - }); + if (v._isFillColorFromUnbreakable) { + // If the item is a fillColor from an unbreakable block + // We have to add it at the beginning of the items body array of the page + delete v._isFillColorFromUnbreakable; + const endOfBackgroundItemsIndex = ctx.backgroundLength[ctx.page]; + page.items.splice(endOfBackgroundItemsIndex, 0, { + type: 'vector', + item: v + }); + } else { + page.items.push({ + type: 'vector', + item: v + }); + } break; case 'image': diff --git a/src/tableProcessor.js b/src/tableProcessor.js index ca2a0efc9..079a651af 100644 --- a/src/tableProcessor.js +++ b/src/tableProcessor.js @@ -476,7 +476,9 @@ TableProcessor.prototype.endRow = function (rowIndex, writer, pageBreaks) { h: bgHeight, lineWidth: 0, color: fillColor, - fillOpacity: fillOpacity + fillOpacity: fillOpacity, + // mark if we are in an unbreakable block + _isFillColorFromUnbreakable: !!writer.transactionLevel }, false, true, writer.context().backgroundLength[writer.context().page]); }