C# – open Word file and convert to PDF

Veröffentlicht von

Open a Word file with C# and convert it to PDF.

In order to work with Word files in C#, we have to add the “Microsoft.Offcie.Interop.Word” reference to the project.

After that, we can open the file:

var application = new Application();
var document = application.Documents.Open(textBoxUrl.Text);
 
//do actions (e.g. export to PDF)
var pdfFileName = "c:\\_temp\\export.pdf";
document.ExportAsFixedFormat(pdfFileName, WdExportFormat.wdExportFormatPDF);
 
//close
application.Quit();

In our example we take the path from an TextBox and export the file to a given location. The path for the Open method can either be a local URL or an URL, for example Sharepoint. However you need to be authenticated with Sharepoint to get this working.

Kommentar hinterlassen

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert