Skip to content

API reference

An orientation map of the public API: the namespaces, the primary entry points, and the exception hierarchy.

Rivoli PDF ships as three packages: Rivoli.Pdf.Core (the model, builders, layout), Rivoli.Pdf (rendering, save/load, security), and the optional Rivoli.Pdf.Html (HTML to PDF conversion). The public surface divides into a handful of namespaces:

NamespaceWhat lives hereKey types
Rivoli.PdfThe root document type and the exception hierarchyDocument, PdfException and subtypes
Rivoli.Pdf.ModelThe document tree: blocks, inlines, styling primitivesSection, Paragraph, Run, Span, Hyperlink, Table, List, ImageBlock, ContainerBlock, PageBreak, Style, Color, PageSize, Margin
Rivoli.Pdf.BuildersThe high-level builder and the fluent extension methodsDocumentBuilder, AddHeading/H1H6, AddParagraph, AddTable, AddImage
Rivoli.PdfSave/load/merge/split, the renderer, and save optionsDocumentExtensions, PdfDocumentRenderer, PdfSaveOptions, PdfGlobalOptions, PdfVersion, PdfAMode, PdfMerger, PdfSplitter
Rivoli.Pdf.SecurityEncryption and permissionsPdfSecuritySettings, PdfPermissions, PdfEncryptionAlgorithm
Rivoli.Pdf.ObjectsThe low-level PDF object model: build files object-by-objectPdfDictionary, PdfArray, PdfName, PdfString, PdfStream, PdfIndirectObject/Reference
Rivoli.Pdf (low-level)Content-stream operators and the file writersPdfContentStream, PdfDocumentWriter, StreamingPdfWriter

For a conceptual tour of how these fit together, start with The document model.

Document (namespace Rivoli.Pdf) is the root. Create it directly or with the Create factory, then add sections.

using Rivoli.Pdf;
using Rivoli.Pdf.Model;
var doc = new Document(); // empty
var doc2 = Document.Create("Title"); // title only
var doc3 = Document.Create("Title", "Author"); // title + author
doc3.DefaultPageSize = PageSize.A4;
doc3.DefaultMargin = Margin.Standard;
Section section = doc3.AddSection(); // create + append (returns the section)

For a single fluent expression that sets page setup and structure together, use DocumentBuilder (namespace Rivoli.Pdf.Builders). See Working with the builder.

Content goes onto a Section through the fluent extension methods in Rivoli.Pdf.Builders. The headings chain (returning Section); the Add* helpers add a block.

using Rivoli.Pdf.Builders;
section
.H1("Quarterly Report")
.AddParagraph("Prepared by the finance team.")
.AddTable(t => t
.Header("Quarter", "Revenue")
.Row("Q1", "$1.2M")
.Row("Q2", "$1.5M"));
section.AddImage("logo.png", width: 120);
section.AddPageBreak();

Every type is also a plain object you can construct and add directly (section.Add(new Paragraph(...))). The two styles interoperate freely; see the builder guide.

The verbs in Rivoli.Pdf.DocumentExtensions are the everyday I/O surface. SavePdf/SavePdfAsync are extension methods on Document; LoadPdf, MergePdfs, and SplitPdf are static helpers.

using Rivoli.Pdf;
document.SavePdf("out.pdf"); // default PdfVersion.Version14
document.SavePdf("out.pdf", PdfVersion.Version17);
await document.SavePdfAsync("out.pdf");
Document loaded = DocumentExtensions.LoadPdf("in.pdf");
DocumentExtensions.MergePdfs("merged.pdf", "a.pdf", "b.pdf");
DocumentExtensions.SplitPdf("in.pdf", "pages.pdf", startPage: 2, count: 3);

enum PdfVersion { Version14, Version15, Version16, Version17 }. See the how-to recipes for each verb in context.

For anything beyond a plain save (security, PDF/A, tagged output, CJK fonts, diagnostics), drive the PdfDocumentRenderer with a PdfSaveOptions.

using Rivoli.Pdf;
using Rivoli.Pdf.Security;
var renderer = new PdfDocumentRenderer("1.7");
renderer.RenderToFile(doc, "secure.pdf", new PdfSaveOptions
{
EnableTaggedPDF = true,
Language = "en-US",
SecuritySettings = new PdfSecuritySettings
{
UserPassword = "open-me",
Algorithm = PdfEncryptionAlgorithm.Aes256,
Permissions = PdfPermissions.Print | PdfPermissions.CopyContents,
},
});
// or renderer.Render(doc, stream, options);

PdfDocumentRenderer exposes Render(doc, stream[, options]) and RenderToFile(doc, path[, options]).

MemberTypePurpose
PdfVersionstring?Output version (e.g. "1.7"); falls back to the global default
EnableTaggedPDFbool?Emit a tagged (accessible) structure tree
IncludeXmpMetadatabool?Embed XMP metadata
PdfAModePdfAMode?PDF/A conformance level (None, PdfA1b, PdfA1a)
SecuritySettingsPdfSecuritySettings?Encryption, passwords, permissions
GenerateFileIDbool?Emit a document /ID
Languagestring?Document language (e.g. "en-US"), required for PDF/A-1a
ProducerNamestring?The /Producer string
CjkFontPathstring?Path to a CJK font for glyph coverage
CjkFontDatabyte[]?In-memory CJK font program (container-friendly); wins over CjkFontPath
DiagnosticsIPdfDiagnostics?Hook for render diagnostics
PageDecoratorAction<PdfPageDecoratorContext>?Per-page overlay hook (watermarks/stamps), invoked after body + header/footer painting

PdfGlobalOptions (static) holds the fallbacks every render inherits: DefaultPdfVersion, DefaultEnableTaggedPDF, DefaultIncludeXmpMetadata, DefaultPdfAMode, DefaultLanguage, ProducerName, and CjkFontPath, plus ResetToDefaults().

TypeNotes
PdfSecuritySettingsUserPassword, OwnerPassword, Algorithm, Permissions, EncryptMetadata
PdfEncryptionAlgorithmNone, Aes128, Aes256
PdfPermissionsFlags: None, Print, ModifyContents, CopyContents, ModifyAnnotations, FillForms, ExtractForAccessibility, AssembleDocument, PrintHighQuality, All

All library exceptions descend from PdfException (namespace Rivoli.Pdf), so a single catch can cover the whole library while still letting you target specific failures.

Exception
└── PdfException (Rivoli.Pdf: base for everything below)
├── PdfIOException (read/write/stream failures)
├── PdfValidationException (invalid model or option combination, e.g. PDF/A + encryption)
├── LayoutException (layout could not be resolved)
├── PdfRenderException (failure during rendering)
└── PdfParseException (failure parsing an input PDF on LoadPdf)
└── PdfPasswordException (encrypted input, wrong/missing password)
try
{
var doc = DocumentExtensions.LoadPdf("locked.pdf");
}
catch (PdfPasswordException)
{
// prompt for a password
}
catch (PdfException ex)
{
// any other library failure
logger.LogError(ex, "PDF operation failed");
}