๐Ÿ“ฆ Compact Serialization

Reduce PDF file size by 20โ€“40% with cross-reference streams and object streams (PDF 1.5+).

C# โ€” Compact Serialization
var doc = new PdfDocument();

// Enable cross-reference streams (PDF 1.5+)
// Replaces the ASCII cross-reference table with
// a compressed binary stream โ€” smaller files.
doc.UseCrossReferenceStreams = true;

// Enable object streams (PDF 1.5+)
// Packs multiple small objects into a single
// compressed stream โ€” further size reduction.
doc.UseObjectStreams = true;

// Build the document as usual...
doc.Info.Title = "Compact PDF";
doc.Language = "en-US";
doc.DisplayDocTitle = true;
var root = doc.EnableTaggedPdf();

var h1 = root.AddChild(StructureType.H1);
var page = doc.AddPage();
page.AddTaggedText(h1, "Compact Serialization",
    72, 720, new PdfTextOptions {
        Font = StandardFont.HelveticaBold,
        FontSize = 20
    });

var p = root.AddChild(StructureType.P);
page.AddTaggedText(p,
    "This PDF uses cross-reference streams " +
    "and object streams for smaller file size.",
    72, 690);

doc.Save("compact.pdf");
// File size is 20-40% smaller than default!
Screenshot comparing two PDF files side by side: the default serialization file at approximately 4.2 KB and the compact serialization file at approximately 2.8 KB, with a green arrow showing the 33% size reduction โ€” both containing identical content

You should see a bold "Compact Serialization" heading and a seven-line paragraph explaining cross-reference streams and object streams. The PDF itself is notably smaller than an equivalent document without these features โ€” check file size in Explorer to confirm (typically ~2.8 KB versus ~4.2 KB for the same content).
File: 18_compact_serialization.pdf

Serialization Options

PropertyDefaultEffect
UseCrossReferenceStreamsfalseBinary xref table โ†’ compressed stream
UseObjectStreamsfalsePacks small objects into compressed streams

โ™ฟ Accessibility Note

Compact serialization does not affect accessibility. All tagged structure, alt text, and metadata are preserved identically โ€” only the internal binary format changes.