From 3ea28fd2009174fe78c4f2c8965905671594950d Mon Sep 17 00:00:00 2001 From: fe-cj Date: Sun, 1 Sep 2024 18:35:59 +0200 Subject: [PATCH] Fixes issue 1836 --- src/ElementWriter.js | 19 +++++++++++++++---- src/TableProcessor.js | 4 +++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/ElementWriter.js b/src/ElementWriter.js index 94cc42033..7ad883929 100644 --- a/src/ElementWriter.js +++ b/src/ElementWriter.js @@ -322,10 +322,21 @@ class ElementWriter extends EventEmitter { 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 dfe8ebde9..e1efef703 100644 --- a/src/TableProcessor.js +++ b/src/TableProcessor.js @@ -490,7 +490,9 @@ class TableProcessor { 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]); }