Working with Enums
Working with Enums
Aspose.PDF FOSS for .NET uses strongly-typed enums throughout its API to
configure document behavior, page appearance, and conversion formats. Rather
than magic strings or integers, most configuration surfaces — from how a PDF
viewer opens a file to which format a Document is saved as — are expressed
as enum values. This page introduces the enum types you will encounter most
often as you work with the library. It is a curated introduction, not an
exhaustive catalog; for the complete list of enum types and every member
value, see the API Reference.
Page Display and Layout
PageMode and PageLayout are properties on Document that control how a
PDF viewer presents the document when it is first opened — whether it shows
outlines, thumbnails, or a particular column layout.
using var doc = Document.Open("input.pdf");
// Show the outline (bookmarks) panel when the document opens
doc.PageMode = PageMode.UseOutlines;
// Display pages in two columns, first page on the left
doc.PageLayout = PageLayout.TwoColumnLeft;
doc.Save("output.pdf");Page Color Model
ColorType describes the color model of a page — RGB, CMYK, grayscale, and
so on. It is exposed on both Page and Color, letting you branch logic
based on how content on a page is actually rendered.
using var doc = Document.Open("input.pdf");
var page = doc.Pages[1];
if (page.ColorType == ColorType.Grayscale)
{
// Apply grayscale-specific handling, e.g. skip color-profile conversion
}Alignment
Several classes expose HorizontalAlignment and VerticalAlignment for
positioning content on the page, while annotation classes add
TextAlignment and Justification for text-specific alignment within a
box. Table, for example, exposes both alignment axes directly.
var table = new Table();
table.HorizontalAlignment = HorizontalAlignment.Center;
table.VerticalAlignment = VerticalAlignment.Center;
page.Paragraphs.Add(table);FreeTextAnnotation (and the Annotation base type) additionally exposes
Justification and TextAlignment for the text inside the annotation:
if (page.Annotations[1] is FreeTextAnnotation freeText)
{
freeText.Justification = Justification.Center;
freeText.Alignment = TextAlignment.Right;
}Load and Save Formats
LoadFormat identifies the source format behind a LoadOptions subclass
(for example, HtmlLoadOptions.LoadFormat is always LoadFormat.HTML),
while SaveFormat selects the output format when calling Document.Save.
var loadOptions = new HtmlLoadOptions();
// loadOptions.LoadFormat == LoadFormat.HTML
using var doc = new Document("input.html", loadOptions);
doc.Save("output.html", SaveFormat.Html);Page Rotation
Rotation describes a page’s rotation angle and is exposed through
Page.Rotate.
var page = doc.Pages[1];
page.Rotate = Rotation.on90;Tips and Best Practices
- Prefer enum overloads over string- or int-based overloads where both exist — they catch invalid values at compile time.
- Match
SaveFormatto the file extension you pass toDocument.Save; a mismatch produces a file with misleading contents or an unusable extension. - Use the
LoadOptionssubclass that corresponds to your source format (e.g.HtmlLoadOptionsfor HTML) rather than relying on format auto-detection alone. - Set both
HorizontalAlignmentandVerticalAlignmenttogether when positioning tables or paragraphs — leaving one at its default can produce unexpected placement. - Treat
ColorTypeas descriptive, not prescriptive: it reports how a page’s color content is currently modeled, not a setting you toggle to convert color spaces.
Common Issues
| Issue | Cause | Fix |
|---|---|---|
| Saved file has the wrong content for its extension | Wrong SaveFormat value passed to Document.Save | Pass the SaveFormat value that matches the target file extension |
| Loaded HTML/XML/etc. content renders incorrectly | Generic LoadOptions used instead of the format-specific subclass | Use the subclass matching the source format, e.g. HtmlLoadOptions |
| Table or annotation appears misaligned on the page | HorizontalAlignment/VerticalAlignment left at their defaults | Explicitly set both properties before adding the object to Paragraphs |
| PDF opens with unexpected viewer behavior (no outline panel, wrong column layout) | Document.PageMode/Document.PageLayout never set | Set both properties before calling Document.Save |
FAQ
What is the difference between PageMode and PageLayout?
PageMode controls viewer UI state on open (for example, whether the
outline or thumbnails panel is visible), while PageLayout controls how
pages are arranged (single page, one column, two columns, and so on).
How do I know which SaveFormat value to use?
Pick the SaveFormat value that matches the output file type you want —
for example, SaveFormat.Html for HTML output or SaveFormat.Pdf to
re-save as PDF.
Can I set both HorizontalAlignment and VerticalAlignment on the same object?
Yes. Classes such as Table expose both properties independently, so you
can combine them to position content on either axis.
Does ColorType let me convert a page’s color space?
No. ColorType reports the color model currently associated with a page
or color value; it does not perform conversion.
Where can I find every enum and every value?
This page covers the most commonly used enums. For the complete set, including every member value, see the API Reference.
API Reference Summary
| Enum | Description |
|---|---|
PageMode | How the PDF viewer displays the document on open (outlines, thumbnails, full-screen, etc.) |
PageLayout | Page layout used when the document is displayed (single page, columns, etc.) |
ColorType | Color model of a page or color value (RGB, CMYK, grayscale, etc.) |
HorizontalAlignment | Horizontal alignment of paragraphs, tables, or annotations |
VerticalAlignment | Vertical alignment of paragraphs, tables, or annotations |
TextAlignment | Horizontal text alignment for annotation text boxes |
Justification | Justification of a free-text annotation’s content |
LoadFormat | Source format selector used by LoadOptions subclasses |
SaveFormat | Output format selector used by Document.Save |
Rotation | Page rotation angle, exposed via Page.Rotate |