Easy as pie. I have a lot of experience using XML, as well as generated PDF documents using an array of libraries including languages such as PHP and ActionScript 3.
How about we develop an accompanying XML file with tags, that you can modify your layout, should you decide to update your template?
That way, you may reposition and completely alter your page layout, without the need to modify your code.