Merged pdf files keep wrong page number

Hi, I am merging pdf files that i have created and they keep their original page number. How can I get the correct page number in the footer in the new merged document?

As an example:

I have pdf file A with 4 pages and it has a footer with page number 1,2,3,4. I have a second pdf file called B that has 7 pages and it has a footer with page number 1,2,3,4,5,6,7. When I merge the two documents to a third new document then the first pages comes from document A and have the numbers 1,2,3,4 and the from document B with 1,2,3,4,5,6,7 so the numbers are 1,2,3,4,1,2,3,4,5,6,7. How can I get the page numbers in the footer to be correct?

I am using java.
Thanks

@HMALMSTR

Could you please share your sample PDF documents with us along with the code snippet that you are using to merge them. We will test the scenario in our environment and address it accordingly.