DocxToPdfRenderer 1.2.2

dotnet add package DocxToPdfRenderer --version 1.2.2
                    
NuGet\Install-Package DocxToPdfRenderer -Version 1.2.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DocxToPdfRenderer" Version="1.2.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DocxToPdfRenderer" Version="1.2.2" />
                    
Directory.Packages.props
<PackageReference Include="DocxToPdfRenderer" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DocxToPdfRenderer --version 1.2.2
                    
#r "nuget: DocxToPdfRenderer, 1.2.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DocxToPdfRenderer@1.2.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DocxToPdfRenderer&version=1.2.2
                    
Install as a Cake Addin
#tool nuget:?package=DocxToPdfRenderer&version=1.2.2
                    
Install as a Cake Tool

DocxToPdfRenderer

NuGet NuGet Downloads License: MIT

A high-performance .NET 8.0 library for converting DOCX files to PDF format with precise table rendering, advanced text formatting, and built-in security validation. Designed for memory-based operations ideal for web services and cloud functions.

Features

  • Precise Table Rendering: Accurate size calculations with improved unit conversion (v1.2.0)
  • Advanced Text Formatting: Strikethrough, underline variants, superscript/subscript, small caps
  • Memory-First API: Primary byte[] → byte[] conversion without file system dependencies
  • Async/Await Support: Full async API with cancellation token support
  • Security Validation: Built-in protection against malicious content and zip bombs
  • Dependency Injection: Modular architecture with service interfaces
  • Complex Documents: Headers, footers, tables, images, and mixed-run formatting
  • Cross-Platform: Windows, Linux, and macOS support

Installation

dotnet add package DocxToPdfRenderer

Requires .NET 8.0 or later.

Quick Start

Basic Usage

using DocxToPdfRenderer;

var converter = new DocxToPdfRenderer();
byte[] pdfBytes = converter.ConvertDocxToPdf(docxBytes);

// Async with cancellation
byte[] pdfBytes = await converter.ConvertDocxToPdfAsync(docxBytes, cancellationToken);

// File conversion
converter.ConvertDocxToPdf("input.docx", "output.pdf");

ASP.NET Core Integration

// Program.cs
builder.Services.AddSingleton<IDocumentConversionService>(sp => {
    var logger = sp.GetRequiredService<ILogger<DocumentConversionService>>();
    return new DocumentConversionService(
        new ParserFactory(), new PdfDocumentComposer(), 
        new DefaultSecurityValidator(), logger);
});

// API endpoint
app.MapPost("/convert", async (HttpRequest req, IDocumentConversionService svc, CancellationToken ct) => {
    using var ms = new MemoryStream();
    await req.Body.CopyToAsync(ms, ct);
    var pdf = await svc.ConvertDocxToPdfAsync(ms.ToArray(), ct);
    return Results.File(pdf, "application/pdf", "converted.pdf");
}).DisableAntiforgery();

Configuration

using DocxToPdfRenderer.Core.Security;

// Security options
var securityOptions = new SecurityOptions
{
    MaxFileSize = 104857600,        // 100MB
    MaxUncompressedSize = 524288000, // 500MB
    ProcessingTimeout = 60000,       // 60 seconds
    MaxCompressionRatio = 100.0,     // Zip bomb protection
    StrictXmlValidation = true
};

var securityValidator = new DefaultSecurityValidator(securityOptions);
var conversionService = new DocumentConversionService(
    new ParserFactory(), 
    new PdfDocumentComposer(), 
    securityValidator, 
    logger);

Supported Features

Document Structure

  • ✅ Paragraphs with mixed-run formatting
  • ✅ Headers, footers, and page numbering
  • ✅ Tables with precise size calculations (v1.2.0)
  • ✅ Images (JPEG, PNG, BMP, GIF)
  • ✅ Lists (numbered and bulleted)
  • ✅ Page breaks and multi-page documents

Text Formatting

  • ✅ Font family, size, colors
  • ✅ Bold, italic, strikethrough (single/double)
  • ✅ Underline variants (dotted, dashed, wavy, etc.)
  • ✅ Superscript/subscript with baseline adjustments
  • ✅ Small caps, all caps, text highlighting
  • ✅ Character spacing and justification
  • ✅ Text alignment (left, right, center, justify)

Table Features (Enhanced v1.2.0)

  • ✅ Accurate width calculations (fixed, percentage, auto)
  • ✅ Cell merging and complex structures
  • ✅ Borders and shading
  • ✅ Intelligent scaling to fit page width

Limitations

  • ❌ Form fields, macros, comments
  • ❌ Embedded objects (Excel, PowerPoint)
  • ❌ Text effects (shadow, outline, emboss)
  • ❌ Complex script support (RTL languages)

Security & Performance

Security Features

  • Input validation with file size limits (default 50MB)
  • Zip bomb protection with compression ratio limits
  • Format validation to verify DOCX structure
  • Timeout support with cancellation tokens
  • Safe error handling without information leakage

Performance Tips

  • Use async methods for web applications
  • Configure appropriate file size limits
  • Consider memory usage for large documents
  • Implement rate limiting for API endpoints

What's New in v1.2.0

  • Enhanced Table Rendering: Precise size calculations with improved unit conversion
  • Better Layout Engine: Intelligent scaling and page layout calculations
  • Advanced Text Support: Extended formatting options and mixed-run handling
  • Improved Architecture: Cleaner separation with utility classes
  • Better Logging: Comprehensive debug information for troubleshooting

Building from Source

git clone https://github.com/Vladimir-Cherepanov/DocxToPdfRenderer.git
cd DocxToPdfRenderer
dotnet restore
dotnet build
dotnet test

Dependencies

  • DocumentFormat.OpenXml - Microsoft's DOCX SDK
  • PdfSharpCore - Cross-platform PDF generation
  • SixLabors.ImageSharp - Image processing
  • Microsoft.Extensions.Logging - Structured logging

Contributing

Contributions are welcome! Please:

  1. Fork and create a feature branch
  2. Follow C# coding conventions
  3. Add tests for new features
  4. Submit a pull request

License

MIT License. See LICENSE file for details.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.2 235 10/9/2025
1.2.1 183 10/5/2025
1.2.0 199 9/30/2025
1.1.0 336 9/16/2025
1.0.0 199 9/9/2025
0.9.0 195 9/9/2025