DocumentToPdfConverter 1.0.4
dotnet add package DocumentToPdfConverter --version 1.0.4
NuGet\Install-Package DocumentToPdfConverter -Version 1.0.4
<PackageReference Include="DocumentToPdfConverter" Version="1.0.4" />
<PackageVersion Include="DocumentToPdfConverter" Version="1.0.4" />
<PackageReference Include="DocumentToPdfConverter" />
paket add DocumentToPdfConverter --version 1.0.4
#r "nuget: DocumentToPdfConverter, 1.0.4"
#:package DocumentToPdfConverter@1.0.4
#addin nuget:?package=DocumentToPdfConverter&version=1.0.4
#tool nuget:?package=DocumentToPdfConverter&version=1.0.4
DocumentToPdfConverter
High-performance open-source .NET library for converting office documents to PDF using LibreOffice headless. Supports DOC, DOCX, XLS, XLSX, ODT, ODS, PPT, PPTX.
License: MIT. Dependencies are MIT/Apache-2.0/BSD compatible. No proprietary libraries (Aspose, IronPDF, Syncfusion, Spire, etc.).
English
Requirements
- .NET 8+
- LibreOffice installed and
sofficeavailable on the system (or setSOFFICE_PATH).
Linux (server/workstations): see INSTALLATION-LINUX.
Installation
dotnet add package DocumentToPdfConverter
Using the package
- Ensure LibreOffice is installed (or set
SOFFICE_PATH). - Create a converter and call
ConvertAsync:
Quick start
using DocumentToPdfConverter;
using DocumentToPdfConverter.LibreOffice;
using Microsoft.Extensions.Options;
var options = new LibreOfficeConverterOptions
{
ProcessTimeout = TimeSpan.FromSeconds(120),
MaxConcurrency = 1,
};
await using var converter = new LibreOfficeConverter(Options.Create(options));
var result = await converter.ConvertAsync("input.docx", "output.pdf");
if (result.Success)
Console.WriteLine($"Converted in {result.Duration.TotalSeconds:F1}s, size: {result.OutputSizeBytes} bytes");
Converting a file from command line (sample)
With LibreOffice installed, you can use the ConsoleApp sample:
dotnet run --project samples/ConsoleApp/ConsoleApp.csproj -- "path/to/document.docx" "path/to/output.pdf"
Example:
dotnet run --project samples/ConsoleApp/ConsoleApp.csproj -- "C:\Users\YourName\Downloads\Technical Specification.docx" "C:\Users\YourName\Downloads\Technical Specification.pdf"
Dependency injection
services.AddDocumentToPdfConverter(opt =>
{
opt.ProcessTimeout = TimeSpan.FromSeconds(120);
opt.MaxConcurrency = 2;
});
// Registers IDocumentConverter and a health check named "libreoffice"
API overview
- ConvertAsync(path, path) – convert a file to a PDF file.
- ConvertAsync(stream, stream, documentType) – convert from/to streams.
- ConvertAsync(ReadOnlyMemory<byte>, documentType, IBufferWriter<byte>) – convert in-memory.
- IsAvailableAsync() – check if LibreOffice is available.
- GetLibreOfficeInfoAsync() – get version and path of the detected installation.
Full usage guide: docs/USAGE.md — all overloads, options, DI, error handling.
See TROUBLESHOOTING for common issues and configuration tips.
Install LibreOffice on Linux (Ubuntu/Debian, RHEL, server group).
Publish package to NuGet.org.
Русский
Требования
- .NET 8+
- Установленный LibreOffice, в системе доступна команда
soffice(или задана переменная окруженияSOFFICE_PATH).
Linux (сервер/рабочие станции): см. INSTALLATION-LINUX.
Установка
dotnet add package DocumentToPdfConverter
Использование пакета
- Убедитесь, что установлен LibreOffice (или задана переменная
SOFFICE_PATH). - Создайте конвертер и вызовите
ConvertAsync:
Быстрый старт
using DocumentToPdfConverter;
using DocumentToPdfConverter.LibreOffice;
using Microsoft.Extensions.Options;
var options = new LibreOfficeConverterOptions
{
ProcessTimeout = TimeSpan.FromSeconds(120),
MaxConcurrency = 1,
};
await using var converter = new LibreOfficeConverter(Options.Create(options));
var result = await converter.ConvertAsync("input.docx", "output.pdf");
if (result.Success)
Console.WriteLine($"Конвертировано за {result.Duration.TotalSeconds:F1} с, размер: {result.OutputSizeBytes} байт");
Конвертация файла из командной строки (пример)
При установленном LibreOffice можно использовать пример ConsoleApp:
dotnet run --project samples/ConsoleApp/ConsoleApp.csproj -- "путь/к/документу.docx" "путь/к/результату.pdf"
Пример:
dotnet run --project samples/ConsoleApp/ConsoleApp.csproj -- "C:\Users\Имя\Downloads\Техническая спецификация.docx" "C:\Users\Имя\Downloads\Техническая спецификация.pdf"
Регистрация в DI
services.AddDocumentToPdfConverter(opt =>
{
opt.ProcessTimeout = TimeSpan.FromSeconds(120);
opt.MaxConcurrency = 2;
});
// Регистрирует IDocumentConverter и проверку здоровья "libreoffice"
Обзор API
- ConvertAsync(path, path) — конвертация файла в PDF.
- ConvertAsync(stream, stream, documentType) — конвертация из потока в поток.
- ConvertAsync(ReadOnlyMemory<byte>, documentType, IBufferWriter<byte>) — конвертация в памяти.
- IsAvailableAsync() — проверка доступности LibreOffice.
- GetLibreOfficeInfoAsync() — получение версии и пути к установленному LibreOffice.
Подробная инструкция по использованию: docs/USAGE.md — все перегрузки, опции, DI, обработка ошибок.
Подробнее о типичных проблемах и настройке: TROUBLESHOOTING.
Установка LibreOffice на Linux (Ubuntu/Debian, RHEL, группа серверов).
Публикация пакета в NuGet.org.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 8.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Options (>= 8.0.0)
- Microsoft.IO.RecyclableMemoryStream (>= 3.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Initial release. Converts DOC, DOCX, XLS, XLSX, ODT, ODS, PPT, PPTX to PDF via LibreOffice headless. File, stream, and in-memory conversion. Process pool with configurable concurrency. DI extension and health check. MS Office font mapping: Calibri→Carlito, Cambria→Caladea, Arial→Liberation Sans, Times New Roman→Liberation Serif (avoids DejaVu by default); disable with ApplyMsOfficeFontMapping = false. MIT license.