fix a few max call stack size exceeded errors

resolves a RangeError when finalizing documents with many images and/or many pages.