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.ColumnWidthsas a space-separated string of point values to control layout. FloatingBoxis useful for absolute positioning — combine withTablefor structured content.HeaderFooter.FromTextsupports{0}as a page-number placeholder.- Add all paragraphs before calling
Save— the layout engine processes content in order. - Use
BorderInfoto add borders to tables, cells, and floating boxes.
Common Issues
| Issue | Cause | Fix |
|---|---|---|
| Table overflows page | Too many rows for one page | The library auto-paginates; adjust margins if needed |
| Header not appearing | ApplyAsHeader called after Save | Apply headers before saving |
| FloatingBox at wrong position | Coordinates measured from top-left in paragraph units | Verify 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 / Method | Description |
|---|---|
Paragraphs | Ordered content elements on a page |
Paragraphs.Add | Append a paragraph element (text, table, graph, etc.) |
Table | Grid layout with rows, cells, and column widths |
Table.ImportArray | Populate table from an array |
Rows | Row collection in a table |
Cells | Cell collection in a table row |
BorderInfo | Border styling for tables, cells, and boxes |
FloatingBox | Absolutely positioned content container |
HeaderFooter | Repeating header or footer content |
HeaderFooter.FromText | Create header/footer from a text template |
PdfPageStamp | Overlay a PDF page as a stamp |