Converting Word document to PDF in ASP.NET Core
Syncfusion® Essential® DocIO Renderer is a .NET Core Word to PDF conversion library (Essential® DocIO and Essential® PDF) used to convert Word documents to PDF in ASP.NET Core applications [C#].
Steps to convert a Word document to PDF programmatically in ASP.NET Core:
- Create a new C# .NET Core console application.
- Install the Syncfusion.DocIORenderer.NET.Core NuGet package as a reference to your .NET Core application from NuGet.org.
- Include the following namespace in the Program.cs file.
C#
using Syncfusion.DocIO.DLS; using Syncfusion.DocIORenderer; using Syncfusion.Pdf; using System.IO;
- Use the following code snippet to create a Word document with “Hello World” text and convert the Word document to PDF.
C#
// Creates a new Word document. WordDocument wordDocument = new WordDocument(); // Add a section and a paragraph in the empty document. wordDocument.EnsureMinimal(); // Append text to the last paragraph of the document. wordDocument.LastParagraph.AppendText("Hello World...!"); // Create an instance for DocIORenderer for Word to PDF conversion. DocIORenderer render = new DocIORenderer(); // Converts Word document to PDF. PdfDocument pdfDocument = render.ConvertToPDF(wordDocument); // Release the resources used by the Word document and DocIO Renderer objects. render.Dispose(); wordDocument.Dispose(); // Save the PDF file. FileStream outputStream = new FileStream(@"Output.pdf", FileMode.CreateNew, FileAccess.Write); pdfDocument.Save(outputStream); // Close the instance of the PDF document object. pdfDocument.Close(); // Dispose of the instance of FileStream. outputStream.Dispose();
A complete working example of how to convert Word document to PDF using .NET Core Word library can be downloaded from WordToPDF_Example.Zip.
By executing the example program, you will get the PDF document as like below.
Take a moment to peruse the documentation, where you can find other file format conversions with code examples and the procedure to deploy the application in Linux OS.
Explore more about the rich set of Syncfusion® Word Framework features.
An online example to convert a Word document to PDF in an ASP.NET Core web application.
Note:
Starting with v16.2.0.x, if you reference Syncfusion® assemblies from a trial setup or the NuGet feed, include a license key in your projects. Refer to the link to learn about generating and registering the Syncfusion® license key in your application to use the components without a trial message.