Tim, yes I absolutely agree to that, as the PDF calculations/handling does differ between the two files.
The same can be said for some other PDF files too.
In my mind, I like to get to a "near identical" format, so that it's easier to see/visualize the abstraction/refactoring that can be done. Having worked with Javascript for awhile, I prefer JSON over XML, but I'm ok with either format.
Try the attached file to see if that helps the situation, or not. The 'Print Preview' option is now available with this script too.
With my basic testing of one item with an 'Invoice' PDF and the Preview were both ok, however, I do not have any controlled items for a full test.
Although I did get an error checking the 'Credit Note' path, I may be missing something for the credit side to work (as a note at the top of the page says), but the query syntax output after error was ok.
Also, if you happen to have a transaction that spans 2 or 3 pages would be worth a test too to ensure no artifacts.
Let us know if you find any issues.
NOTE: I'd first save (or backup) the current file before replacing!