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 SaveFormat to the file extension you pass to Document.Save; a mismatch produces a file with misleading contents or an unusable extension.
  • Use the LoadOptions subclass that corresponds to your source format (e.g. HtmlLoadOptions for HTML) rather than relying on format auto-detection alone.
  • Set both HorizontalAlignment and VerticalAlignment together when positioning tables or paragraphs — leaving one at its default can produce unexpected placement.
  • Treat ColorType as 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

IssueCauseFix
Saved file has the wrong content for its extensionWrong SaveFormat value passed to Document.SavePass the SaveFormat value that matches the target file extension
Loaded HTML/XML/etc. content renders incorrectlyGeneric LoadOptions used instead of the format-specific subclassUse the subclass matching the source format, e.g. HtmlLoadOptions
Table or annotation appears misaligned on the pageHorizontalAlignment/VerticalAlignment left at their defaultsExplicitly 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 setSet 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

EnumDescription
PageModeHow the PDF viewer displays the document on open (outlines, thumbnails, full-screen, etc.)
PageLayoutPage layout used when the document is displayed (single page, columns, etc.)
ColorTypeColor model of a page or color value (RGB, CMYK, grayscale, etc.)
HorizontalAlignmentHorizontal alignment of paragraphs, tables, or annotations
VerticalAlignmentVertical alignment of paragraphs, tables, or annotations
TextAlignmentHorizontal text alignment for annotation text boxes
JustificationJustification of a free-text annotation’s content
LoadFormatSource format selector used by LoadOptions subclasses
SaveFormatOutput format selector used by Document.Save
RotationPage rotation angle, exposed via Page.Rotate

See Also