How the pdf-writer API works
mainThe pdf-writer API uses a hierarchical, step-by-step approach to constructing PDF documents. The entry point is the Pdf struct, which manages a single large internal buffer for the entire document.
To create specific PDF objects, you call methods on the top-level Pdf writer. These methods return specialized writers that follow a consistent pattern:
- They borrow the main buffer mutably.
- They expose a builder pattern to write individual fields in a strongly typed manner.
- They finalize the object automatically when the specialized writer is dropped.
While most writers borrow from the parent to minimize allocations, some specialized builders (like the one for Content streams) maintain their own internal buffers.