Hello hope your doing well. Thanks for reaching out!
Step 1: Install Syncfusion DocIO
- Open NuGet Package Manager
- Run this command: Install-Package Syncfusion.DocIO.Net.Core
- Step 2: Add Required Namespaces
At the top of your .cs file, add:
using Syncfusion.DocIO; using Syncfusion.DocIO.DLS; using Syncfusion.DocIORenderer; using Syncfusion.Pdf;
Step 3: Load and Convert the Word Document
// Load the Word document WordDocument wordDocument = new WordDocument(Server.MapPath("~/Files/input.docx"));
// Convert to PDF DocIORenderer renderer = new DocIORenderer(); PdfDocument pdfDocument = renderer.ConvertToPDF(wordDocument);
Step 4: Save the PDF File
// Save the PDF to disk pdfDocument.Save(Server.MapPath("~/Files/output.pdf"));
// Close documents pdfDocument.Close(); wordDocument.Close();
Step 5: Display or Download the PDF
Response.ContentType = "application/pdf"; Response.TransmitFile(Server.MapPath("~/Files/output.pdf")); Response.End();