1. GroupDocs.Conversion
  2. /
  3. GroupDocs.Conversion for .NET
  4. /
  5. GroupDocs.Conversion
  6. /
  7. FluentConverter

FluentConverter

FluentConverter class

Class for fluent conversion setup.

public static class FluentConverter

Methods

Name Description
static Load(Func<Stream>) Configure source document stream
static Load(Func<Stream[]>) Configure set of source documents streams
static Load(string) Configure source document for conversion
static Load(string[]) Configure set of source documents
static WithEvents(Action<ConversionEvents>) Entry-stage variant of the fluent chain that starts with conversion lifecycle event handlers. Sits at the same entry stage as WithSettings, and the resulting ConversionEvents bag fires on every conversion run by the converter.
static WithSettings(Func<ConverterSettings>) Configure conversion settings

Remarks

Sample fluent conversion usage:

var converter = FluentConverter.Create();
FluentConverter.Load("")
    .ConvertTo("")
    .Convert();
// Recommended: aggregate handlers via WithEvents at the early stage (before Load).
FluentConverter
    .WithEvents(e =>
    {
        e.OnDocumentConverted = ctx       => Console.WriteLine($"Done: {ctx.SourceFileName}");
        e.OnDocumentFailed    = (ctx, ex) => Console.Error.WriteLine(ex.Message);
    })
    .Load("input.docx")
    .ConvertTo("output.pdf").WithOptions(new PdfConvertOptions())
    .Convert();
// Per-page mirror: per-page handlers via WithEvents at the early stage.
FluentConverter
    .WithEvents(e =>
    {
        e.OnPageConverted = ctx       => Console.WriteLine($"page {ctx.Page} done");
        e.OnPageFailed    = (ctx, ex) => Console.Error.WriteLine($"page {ctx.Page}: {ex.Message}");
    })
    .Load("input.pdf")
    .ConvertByPageTo(ctx => new FileStream($"page-{ctx.Page}.png", FileMode.Create))
    .WithOptions(new ImageConvertOptions { Format = ImageFileType.Png })
    .Convert();
// Legacy chain still compiles unchanged (now backed by the obsolete staged interfaces):
FluentConverter.WithSettings(() => new ConverterSettings())
    .Load("").WithOptions(new PdfLoadOptions())
    .ConvertTo("").WithOptions(new PdfConvertOptions())
    .OnConversionCompleted(convertedDocumentStream => { })
    .Convert();
FluentConverter.Load("").GetPossibleConversions();
FluentConverter.Load("").GetDocumentInfo();
FluentConverter.Load("").WithOptions(new PdfLoadOptions()).GetPossibleConversions();
FluentConverter.Load("").WithOptions(new PdfLoadOptions()).GetDocumentInfo();

See Also