Page Generation

Page Generation

Aspose.PDF FOSS for .NET provides a paragraph-based layout engine for generating PDF content. Tables, floating boxes, headers/footers, and stamps let you build structured pages without manually constructing content-stream operators.


Adding paragraphs

Page.Paragraphs is the entry point for adding content elements.

using var doc = new Document();
var page = doc.Pages.Add();

page.Paragraphs.Add(new TextFragment("Hello, PDF!"));
doc.Save("hello.pdf");

Tables

Table supports rows, cells, column widths, borders, and text state.

var table = new Table();
table.ColumnWidths = "100 200 100";

var row = table.Rows.Add();
row.Cells.Add("Name");
row.Cells.Add("Description");
row.Cells.Add("Price");

page.Paragraphs.Add(table);

Cell formatting

Cells.Add returns a Cell where you can configure borders, padding, and nested content.

var cell = row.Cells.Add("Styled cell");
cell.Border = new BorderInfo(BorderSide.All, 0.5f);
cell.Margin = new MarginInfo(5, 5, 5, 5);

Floating boxes

FloatingBox positions content at absolute coordinates on the page.

var box = new FloatingBox(200, 100);
box.Left = 72;
box.Top = 700;
box.Paragraphs.Add(new TextFragment("Positioned text"));
page.Paragraphs.Add(box);

Headers and footers

HeaderFooter adds repeating content at the top or bottom of pages.

var header = HeaderFooter.FromText("Document Title");
header.ApplyAsHeader(page);

var footer = HeaderFooter.FromText("Page {0}");
footer.ApplyAsFooter(page);

Page stamps

PdfPageStamp overlays content from one PDF page onto another.

var stamp = new PdfPageStamp("watermark.pdf");
stamp.Put(page);

Tips and Best Practices

  • Use Table.ColumnWidths as a space-separated string of point values to control layout.
  • FloatingBox is useful for absolute positioning — combine with Table for structured content.
  • HeaderFooter.FromText supports {0} as a page-number placeholder.
  • Add all paragraphs before calling Save — the layout engine processes content in order.
  • Use BorderInfo to add borders to tables, cells, and floating boxes.

Common Issues

IssueCauseFix
Table overflows pageToo many rows for one pageThe library auto-paginates; adjust margins if needed
Header not appearingApplyAsHeader called after SaveApply headers before saving
FloatingBox at wrong positionCoordinates measured from top-left in paragraph unitsVerify units match your expectations

FAQ

Can I create multi-page tables?

Yes. When a table exceeds the available page height, it automatically continues on the next page.

How do I add images to table cells?

Create an Image paragraph and add it to the cell’s Paragraphs collection.

Can I import data from an array into a table?

Yes. Use Table.ImportArray to populate a table from a two-dimensional array.


API Reference Summary

Class / MethodDescription
ParagraphsOrdered content elements on a page
Paragraphs.AddAppend a paragraph element (text, table, graph, etc.)
TableGrid layout with rows, cells, and column widths
Table.ImportArrayPopulate table from an array
RowsRow collection in a table
CellsCell collection in a table row
BorderInfoBorder styling for tables, cells, and boxes
FloatingBoxAbsolutely positioned content container
HeaderFooterRepeating header or footer content
HeaderFooter.FromTextCreate header/footer from a text template
PdfPageStampOverlay a PDF page as a stamp

See Also