DocxXlsx.PDFConverter
0.0.3
dotnet add package DocxXlsx.PDFConverter --version 0.0.3
NuGet\Install-Package DocxXlsx.PDFConverter -Version 0.0.3
<PackageReference Include="DocxXlsx.PDFConverter" Version="0.0.3" />
<PackageVersion Include="DocxXlsx.PDFConverter" Version="0.0.3" />
<PackageReference Include="DocxXlsx.PDFConverter" />
paket add DocxXlsx.PDFConverter --version 0.0.3
#r "nuget: DocxXlsx.PDFConverter, 0.0.3"
#:package DocxXlsx.PDFConverter@0.0.3
#addin nuget:?package=DocxXlsx.PDFConverter&version=0.0.3
#tool nuget:?package=DocxXlsx.PDFConverter&version=0.0.3
PDFConverter
A lightweight, free and open-source .NET library that converts DOCX and XLSX files to PDF using OpenXML SDK and PdfSharp/MigraDoc. No Microsoft Office installation required.
Why This Library?
I don't currently have the budget to pay for a licensed library to convert DOCX and XLSX files to PDF, even though there are many very good options on the market. So, I decided to build my own converter. It may or may not fit your needs. It's not the fastest option if you're looking for high performance, but it's good enough for me, especially considering that it's free. For simple files with simple objects, it should be enough.
This project was built with significant help from GitHub Copilot — from diagnosing tricky OpenXML quirks to fixing MigraDoc rendering issues, Copilot was an invaluable coding partner throughout the entire development process.
Features
- DOCX → PDF — paragraphs, tables, images, headers/footers, styles, hyperlinks, VML textboxes, emoji
- XLSX → PDF — cell formatting, merged cells, column widths, images (including floating images that overflow rows), connector shape rendering (signature lines)
- Multiple input formats: file path,
Stream, orbyte[] - Output to file or
byte[]for in-memory workflows - Embedded emoji font (Noto Emoji) for cross-platform rendering
- No Office interop — runs on servers and containers
Installation
dotnet add package DocxXlsx.PDFConverter
Quick Start
using PDFConverter;
// DOCX to PDF — from file
Converters.DocxToPdf("report.docx", "report.pdf");
// DOCX to PDF — from stream
using var stream = File.OpenRead("report.docx");
Converters.DocxToPdf(stream, "report.pdf");
// DOCX to PDF — get bytes (no file I/O)
byte[] docxBytes = File.ReadAllBytes("report.docx");
byte[] pdfBytes = Converters.DocxToPdfBytes(docxBytes);
// XLSX to PDF
Converters.XlsxToPdf("data.xlsx", "data.pdf");
// XLSX to PDF — get bytes
byte[] xlsxBytes = File.ReadAllBytes("data.xlsx");
byte[] pdfBytes2 = Converters.XlsxToPdfBytes(xlsxBytes);
For more usage examples, see the Client Documentation.
Font Registration
To ensure fonts used in documents are available for PDF rendering:
// Register all fonts from a directory
OpenXmlHelpers.RegisterFontsFromDirectory("/path/to/fonts");
// Register specific font mappings
OpenXmlHelpers.RegisterFontMappings(new Dictionary<string, string>
{
{ "Calibri", "/path/to/Calibri.ttf" },
{ "Arial MT", "/path/to/ArialMT.ttf" }
});
Supported Features
| Feature | DOCX | XLSX |
|---|---|---|
| Text formatting (bold, italic, underline, color, size) | ✅ | ✅ |
| Paragraph alignment and indentation | ✅ | — |
| Tables with borders and shading | ✅ | ✅ |
| Conditional table formatting (header row, banded rows) | ✅ | — |
| Inline and floating images | ✅ | ✅ |
| Connector shapes (signature lines) | — | ✅ |
| Image cropping (srcRect) | ✅ | — |
| Headers and footers | ✅ | — |
| Hyperlinks | ✅ | — |
| VML textboxes | ✅ | — |
| Emoji | ✅ | — |
| Tab stops | ✅ | — |
| Merged cells | ✅ | ✅ |
| Landscape orientation | ✅ | — |
Known Limitations
- Font substitution: If a document uses fonts not installed on the system, PdfSharp falls back to a default font which may cause minor layout differences.
- EMF/WMF images: Vector image formats are not supported by PdfSharp and will be skipped.
- Color emoji: Only monochrome emoji glyphs (Noto Emoji) are rendered; color emoji (COLR/CPAL) is not supported.
- Image cropping:
srcRectcropping usesSystem.Drawing.Bitmapwhich is Windows-only. On other platforms, the uncropped image is used as a graceful fallback. - Character width scaling: The
w:wattribute is not supported by MigraDoc. - Complex layouts: Very complex Office features (advanced VML, SmartArt, charts) may not be reproduced exactly.
Building & Contributing
See the Developer Documentation for project structure, build instructions, and contribution guidelines.
dotnet build
dotnet test
License
The embedded Noto Emoji font is licensed under the SIL Open Font License 1.1.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- DocumentFormat.OpenXml (>= 3.4.1)
- PdfSharp-MigraDoc (>= 6.2.4)
- System.Drawing.Common (>= 10.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.