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
maxInstancesintMaximum number of worker processes.
minHotStandbyintNumber of workers to start immediately and keep warm.
idleTimeoutTimeSpanTime after which idle workers (beyond hot standby) are shut down.
workerExePathstringOptional path to the worker executable. If null or empty, it will be resolved automatically.
loggerILoggerOptional logger. When
null, logging is disabled.installPathstringOptional 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
inputStreamStreamStream containing the input document.
outputStreamStreamStream where the PDF will be written.
timeoutTimeSpan?Optional timeout for the conversion operation, when specified.
optionsPdfOptionsOptional PdfOptions controlling quality, compliance, security, and layout. When
null, the LibreOffice defaults are used.loggerILogger<Converter>Optional ILogger<TCategoryName> for logging conversion progress and errors.
Returns
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
inputFilestringPath to the input document.
outputFilestringPath where the PDF will be written.
timeoutTimeSpan?Optional timeout for the conversion operation, when specified.
optionsPdfOptionsOptional PdfOptions controlling quality, compliance, security, and layout. When
null, the LibreOffice defaults are used.loggerILoggerOptional logger for the conversion operation. When
null, the default logger is used (when set from the constructor).
Returns
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()