Skip to content

Latest commit

 

History

History
89 lines (70 loc) · 2.81 KB

File metadata and controls

89 lines (70 loc) · 2.81 KB

Getting Started with FluentDocs

FluentDocs is a set of .NET libraries for generating documents, spreadsheets, presentations, and charts from a fluent builder API.

Installation

Install from nuget.org:

# All generators + chart rendering
dotnet add package FluentDocs

# Or install individual packages
dotnet add package FluentDocs.Documents.Docx
dotnet add package FluentDocs.Documents.Pdf
dotnet add package FluentDocs.Documents.Markdown
dotnet add package FluentDocs.Tables
dotnet add package FluentDocs.Presentations
dotnet add package FluentDocs.Charts

Registration

Register all generators and chart rendering in one call:

services.AddFluentDocs();

See dependency-injection.md for granular registration options.

Quick Example

// Inject the generator
public class ReportService(IEnumerable<IFileGenerator> generators)
{
    public async Task<byte[]> GeneratePdfReportAsync()
    {
        var generator = generators.First(g => g.SupportedFormat == GeneratedFileFormat.Pdf);

        var document = GenerationBuilder.Document()
            .ForFormat(GeneratedFileFormat.Pdf)
            .WithFileName("monthly-report")
            .WithMetadata(m => m
                .Title("Monthly Report")
                .Author("Finance Team"))
            .WithPageSetup(p => p
                .WithPageSize(PageSize.A4)
                .WithMargins(25, 25, 25, 25))
            .AddSection(s => s
                .AddHeading("Q4 Financial Summary", HeadingLevel.H1)
                .AddParagraph("Revenue increased by 15% year over year.")
                .AddTable(t => t
                    .AddColumn("Quarter")
                    .AddColumn("Revenue")
                    .AddColumn("Growth")
                    .AddRow(r => r.AddCell("Q1").AddCell("$1.2M").AddCell("+12%"))
                    .AddRow(r => r.AddCell("Q2").AddCell("$1.4M").AddCell("+16%"))))
            .Build();

        var result = await generator.GenerateAsync(document);

        if (result is GenerationResult.Succeeded success)
            return success.Content;

        throw new InvalidOperationException("Generation failed");
    }
}

Supported Formats

Package Formats
FluentDocs.Documents.Pdf PDF
FluentDocs.Documents.Docx DOCX
FluentDocs.Documents.Markdown Markdown, PlainText
FluentDocs.Tables XLSX, CSV, TSV
FluentDocs.Presentations PPTX
FluentDocs.Charts PNG, SVG (chart images)

Next Steps