Fixed a bug where the generated PDF contained ill-sorted elements.