Paragraphs being displaced after replacement by addText

Product: PDFNet-node

Product Version: 9.2.0-1

Please give a brief summary of your issue:
Paragraphs being displaced after replacement by addText

Please describe your issue and provide steps to reproduce it:
At first, I am finding the bounding coordinates by iteratively joining lines. Then, I replace the text in the area of the paragraph with new paragraph text with the addText function of ContentReplacer. The y1 of the area I give to the addText function is extended until the y2 of the next paragraph. However, I need to do this multiple times and it seems that every time I make the replacement, the paragraph is displaced slightly upwards, so if there is a paragraph closely on top, it would merge with that paragraph on the next iteration.

Relevant code:
// para is the coordinates of the para
const { x1, y2, y1 } = para;
// paras is an array contaning coordinates and text of other paras, I change the y1 of current para to
// extend until the next para
const nextParaStartY = Math.min((paras[paraInd+1]?.y2 || 20) + 20, y1 + 5); // maximum extend until next para or end of page
let replacer = await PDFNet.ContentReplacer.create();
const pageWidth = await page.getPageWidth();
await replacer.addText(new PDFNet.Rect(x1, nextParaStartY, Math.max(pageWidth - PAGE_MARGIN_PERCENT*pageWidth, pageWidth - x1) , y2), newText);
await replacer.process(page);

Any idea on why this happens? Thanks in advance.

Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:

Guides:APIs:Forums:

Thank you for contacting us about this. To get a better understanding of the issue, could you please also provide us with the file you are working with, a full sample where we are able to reproduce the issue?

Thank you in advance.