Table of Contents

Class Converter

Namespace
LibreOfficeKit
Assembly
LibreOfficeKit.dll

Manages a pool of LibreOffice worker processes for document-to-PDF conversion.

public class Converter : IAsyncDisposable
Inheritance
Converter
Implements
Inherited Members

Remarks

High-level document converter that manages a pool of worker processes. Each worker is a separate OS process running its own LibreOfficeKit instance, communicating with the host via named pipes.

Features:

  • Hot standby: pre-spawned workers ready for immediate use
  • On-demand scaling: additional workers up to maxInstances
  • Idle timeout: workers shut down after idleTimeout of inactivity
  • Health monitoring: background task detects crashes/hangs
  • Request queue: requests queue when all workers are busy
  • IDisposable: proper cleanup of all workers and resources

Constructors

Converter(int, int, TimeSpan, string?, ILogger?, string?)

Creates a new Converter with the specified pool configuration. Hot standby workers are spawned immediately.

public Converter(int maxInstances, int minHotStandby, TimeSpan idleTimeout, string? workerExePath = null, ILogger? logger = null, string? installPath = null)

Parameters

maxInstances int

Maximum number of worker processes.

minHotStandby int

Number of workers to start immediately and keep warm.

idleTimeout TimeSpan

Time after which idle workers (beyond hot standby) are shut down.

workerExePath string

Optional path to the worker executable. If null or empty, it will be resolved automatically.

logger ILogger

Optional logger. When null, logging is disabled.

installPath string

Optional custom installation path for LibreOffice.

Methods

ConvertToPdfAsync(Stream, Stream, TimeSpan?, PdfOptions?, ILogger<Converter>?)

Converts a document to PDF using streams. The input stream is written to a temp file, converted, then the output is read back into the output stream.

public Task ConvertToPdfAsync(Stream inputStream, Stream outputStream, TimeSpan? timeout = null, PdfOptions? options = null, ILogger<Converter>? logger = null)

Parameters

inputStream Stream

Stream containing the input document.

outputStream Stream

Stream where the PDF will be written.

timeout TimeSpan?

Optional timeout for the conversion operation, when specified.

options PdfOptions

Optional PdfOptions controlling quality, compliance, security, and layout. When null, the LibreOffice defaults are used.

logger ILogger<Converter>

Optional ILogger<TCategoryName> for logging conversion progress and errors.

Returns

Task

Exceptions

ArgumentOutOfRangeException

Thrown when the timeout is less than or equal to zero.

FileNotFoundException

Thrown when the input file does not exist.

TimeoutException

Thrown when the conversion times out.

ConversionFailedException

Thrown when the conversion fails.

ConvertToPdfAsync(string, string, TimeSpan?, PdfOptions?, ILogger?)

Converts a document to PDF using file paths.

public Task ConvertToPdfAsync(string inputFile, string outputFile, TimeSpan? timeout = null, PdfOptions? options = null, ILogger? logger = null)

Parameters

inputFile string

Path to the input document.

outputFile string

Path where the PDF will be written.

timeout TimeSpan?

Optional timeout for the conversion operation, when specified.

options PdfOptions

Optional PdfOptions controlling quality, compliance, security, and layout. When null, the LibreOffice defaults are used.

logger ILogger

Optional logger for the conversion operation. When null, the default logger is used (when set from the constructor).

Returns

Task

Remarks

Default timeout is 60 minutes, which should be sufficient for even very large documents. Adjust as needed for your use case.

Exceptions

ArgumentOutOfRangeException

Thrown when the timeout is less than or equal to zero.

FileNotFoundException

Thrown when the input file does not exist.

TimeoutException

Thrown when the conversion times out.

FilePasswordProtectedException

Thrown when the document is password-protected.

FileTypeNotSupportedException

Thrown when the file type is not supported.

ConversionFailedException

Thrown when the conversion fails.

Dispose()

Synchronously disposes the converter, shutting down all workers and releasing resources.

public void Dispose()

DisposeAsync()

Asynchronously disposes the converter, gracefully shutting down all workers and releasing resources.

public ValueTask DisposeAsync()

Returns

ValueTask