Reverse the order of pages in a PDF document instantly.
A PDF document is essentially a database of objects. The pages you see on screen are determined by a specific array called the /Kids array inside the root Pages dictionary.
This array holds references (pointers) to the actual page objects scattered throughout the file.
To reverse an entire document, we do not need to read, decode, or rewrite the heavy graphical content of every single page.
Instead, our WebAssembly engine simply takes the /Kids array (e.g., [1, 2, 3, 4]) and runs a standard array reversal algorithm in memory (resulting in [4, 3, 2, 1]). When the file is serialized and saved, any PDF viewer will follow these pointers and display the book backwards.
Because reversing an array of integers is an O(n) time complexity operation that requires almost zero memory allocation, this tool can reverse a 10,000-page PDF in a fraction of a millisecond.
The only computational cost is parsing the initial file structure and writing the new file bytes back to disk.
Why is reversing a PDF document so fast?