Lopdf: Rust library for PDF document manipulation
Why keeping everything in memory as high-level objects until finallay serializing the entire document? Normally a PDF document won’t be very large, ranging form tens of KB to hundreds of MB. By keep the whole document in memory, stream length can be pre-calculated, no need to use a reference object for the Length entry, the resulting PDF file is smaller for distribution and faster for PDF consumers to process.
Source: github.com