๐ Multi-Page Documents
Create documents with multiple pages, reusable headers/footers, and consistent formatting.
C# โ Multi-Page Document
var doc = new PdfDocument();
doc.Info.Title = "Multi-Page Document";
doc.Language = "en-US";
doc.DisplayDocTitle = true;
var root = doc.EnableTaggedPdf();
// Create a reusable header (Form XObject)
var header = doc.CreateFormXObject(612, 30);
header.DrawLine(72, 0, 540, 0, new PdfDrawOptions {
StrokeColor = new PdfColor(0.7, 0.7, 0.7)
});
header.AddText("Multi-Page Document โ ObviousPDF",
72, 8, new PdfTextOptions {
Font = StandardFont.HelveticaOblique,
FontSize = 8,
Color = new PdfColor(0.5, 0.5, 0.5)
});
// Generate pages
string[] chapters = { "Introduction", "Core Concepts", "Conclusion" };
for (int i = 0; i < chapters.Length; i++)
{
var page = doc.AddPage();
// Reusable header as artifact
page.BeginArtifact(PdfArtifactType.Pagination);
page.AddFormXObject(header, 0, 762);
page.EndArtifact();
// Tagged chapter heading
var sect = root.AddChild(StructureType.Sect);
var h1 = sect.AddChild(StructureType.H1);
page.AddTaggedText(h1,
$"Chapter {i + 1}: {chapters[i]}",
72, 720, new PdfTextOptions {
Font = StandardFont.HelveticaBold,
FontSize = 20
});
// Page number artifact
page.AddArtifactText(
$"Page {i + 1} of {chapters.Length}",
270, 30, PdfArtifactType.Pagination);
}
doc.Save("multi_page.pdf");
You should see three pages, each sharing the same italic gray header line at the top and a centered "Page N of 3" footer. Bold chapter headings read "Chapter 1: Introduction", "Chapter 2: Core Concepts", and "Chapter 3: Conclusion".
File: 03_multi_page.pdf