Thank you all for the help and collaboration. In the end, I managed to solve the problem in the following way: I created a pageMap mapping. Then, instead of using page.name or documentOffset, the script directly accesses pageMap[i] to get the corresponding page number. I want to repeat that I have no programming knowledge; everything was solved using artificial intelligence since this code is for personal use. If I had needed it, I would have contacted a professional. Best regards, and once again, thank you very much.