Free .NET Library for Microsoft® Word Documents Conversion to PDF & HTML

Open-Source Library to Convert DOCX to PDF

What is DOCXToPDFConverter?

There are a bunch of open-source APIs available that allow generating PDF document via code. The problem with it is that, for even one line of change, the developer has to update the code, test it, release a new version and end user will verify the update. The process is too long and hectic for small updates like these. DOCXToPDFConverter has been developed with aim to allow end users to update the output document via Word. End users can update the DOCX and the API will generate an output PDF file for it. Not only you can convert DOCX to PDF, but can also get HTML as output.

While working with DOCX to PDF and DOCX to HTML conversion the API parses source document, and introduces the dynamic content into predefined placeholders. The API works on Windows, Linux and macOS.

Previous Next

Getting Started with DOCXToPDFConverter

First of all, you require to have .NETCoreApp 2.1. After that, please download the repository manually from GitHub or install it from NuGet.

Installation DOCXToPDFConverter from NuGet

 Install-Package DocXToPdfConverter

Convert DOCX to PDF via Free .NET API

DOCXToPDFConverter allows .NET programmers to convert DOCX to PDF programmatically. In order to convert DOCX to PDF, define a source file, define path to LibreOffice, set placeholders, and convert the document using Convert() method. Following code snippet demonstrates how to convert a DOCX to PDF format.

Convert DOCX to PDF in C#

  1. Initialize path to LibreOffice soffice.exe
  2. Initialize placeholders which you want to use in your Word Documents. There are 3 types of placeholders: one for plain text, one for table rows and one for images
  3. Initialize ReportGenerator and pass locationOfLibreOfficeSoffice as parameter
  4. Convert DOCX to PDF by using ReportGenerator's Convert() method and pass input DOCX file path, output PDF path and placeholders as parameters.

Free .NET API to Convert DOCX to PDF

// Initialize LibreOffice soffice.exe filepath
string locationOfLibreOfficeSoffice = @"C:\PortableApps\LibreOfficePortable\App\libreoffice\program\soffice.exe";
// Define placeholders
placeholders.NewLineTag ="
"; placeholders.TextPlaceholderStartTag ="##"; placeholders.TextPlaceholderEndTag ="##"; placeholders.TablePlaceholderStartTag ="=="; placeholders.TablePlaceholderEndTag ="=="; placeholders.ImagePlaceholderStartTag ="++"; placeholders.ImagePlaceholderEndTag ="++"; // Initialize report generator var test = new ReportGenerator(locationOfLibreOfficeSoffice); // Convert DOCX to PDF test.Convert("Test-Template.docx","Test-Template-out.pdf", placeholders);