Converting DOCX File to PDF C #

3

I have an application and I need to convert a file DOCX to PDF without losing the formatting.

I found some DLLs that help, but for corporate use you have to buy licenses so it gets tricky.

Complementing I did some more research and found some posts that use Microsoft.Office.Interop.Word

    
asked by anonymous 29.08.2017 / 17:26

1 answer

2

It is very easy to use the Microsoft.Office.Interop.Word library to convert to PDF. However, it is necessary for MS-Word to be installed on the machine where the application will run.

An example code in C# to do the conversion is as follows:

string arqDoc = @"C:\Desenv\DocTeste.docx";
string arqPdf = @"C:\Desenv\DocTeste.pdf";

var appWord = new Microsoft.Office.Interop.Word.Application();
var wordDocument = appWord.Documents.Open(arqDoc);

wordDocument.ExportAsFixedFormat(arqPdf, Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF);       

wordDocument.Close();
    
27.09.2017 / 06:03