Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert word file(.docx & doc) to .pdf using c#

Tags:

c#

How i can convert word file (.docx & doc ) to .pdf in c# without using SaveAs() or Save() method ? or without uploading on server?

like image 387
Shahida Avatar asked Feb 06 '23 13:02

Shahida


1 Answers

Try this, it works for me:

using Microsoft.Office.Interop.Word;

var appWord = new Application();
if (appWord.Documents != null)
{
    //yourDoc is your word document
    var wordDocument = appWord.Documents.Open(yourDoc);
    string pdfDocName = "pdfDocument.pdf";
    if (wordDocument != null)
    {                                         
       wordDocument.ExportAsFixedFormat(pdfDocName,   
       WdExportFormat.wdExportFormatPDF);
       wordDocument.Close();
    }
       appWord.Quit();
}
like image 180
Human Avatar answered Feb 12 '23 12:02

Human