Expand description
§PDF Serializer
Takes the laid-out pages from the layout engine and writes a valid PDF file.
This is a from-scratch PDF 1.7 writer. We write the raw bytes ourselves because it gives us full control over the output and makes the engine self-contained. The PDF spec is verbose but the subset we need for document rendering is manageable.
§PDF Structure (simplified)
%PDF-1.7 <- header
1 0 obj ... endobj <- objects (fonts, pages, content streams, etc.)
2 0 obj ... endobj
...
xref <- cross-reference table (byte offsets of each object)
trailer <- points to the root object
%%EOF§Font Embedding
Standard PDF fonts (Helvetica, Times, Courier) use simple Type1 references. Custom TrueType fonts are embedded as CIDFontType2 with Identity-H encoding, producing 5 PDF objects per font: FontFile2, FontDescriptor, CIDFont, ToUnicode CMap, and the root Type0 dictionary.