Converting DOCX File to PDF C#

Asked

Viewed 505 times

3

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

I found some DLL that help, but for corporate use have to buy license so it gets complicated.

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

1 answer

2


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

An example of code in C# to make 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();
  • It works perfectly, very good.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.