Articles in this section
Category / Section

How to convert Word to PDF using C# and VB.NET in WF application?

2 mins read

Syncfusion Essential PDF is a .NET PDF Library used to create, read, and edit PDF documents. Using this library, you can convert Word document to PDF in C# and VB.NET.

Steps to convert word document to PDF programmatically:

  1. Create a new C# console application project.

Create console application in WinForms PDF

  1. Install the Syncfusion.DocToPDFConverter.WinForms NuGet packages as reference to your .NET Framework application from NuGet.org.

NuGet package reference in WinForms PDF

  1. Include the following namespaces in the Program.cs file.

C#

using Syncfusion.Pdf;
using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;
using Syncfusion.DocToPDFConverter;

 

VB.NET

Imports Syncfusion.Pdf
Imports Syncfusion.DocIO
Imports Syncfusion.DocIO.DLS
Imports Syncfusion.DocToPDFConverter

 

  1. Use the following code snippet to convert Word document to PDF.

C#

//Load an existing Word document
WordDocument wordDocument = new WordDocument("Sample.docx", FormatType.Docx);
//Create an instance of DocToPDFConverter
DocToPDFConverter converter = new DocToPDFConverter();
//Convert Word document into PDF document
PdfDocument pdfDocument = converter.ConvertToPDF(wordDocument);
//Save the PDF file
pdfDocument.Save("WordtoPDF.pdf");
//Close the instance of document objects
pdfDocument.Close(true);
wordDocument.Close();
//This will open the PDF file so, the result will be seen in default PDF viewer
System.Diagnostics.Process.Start("WordtoPDF.pdf");

 

VB.NET

'Load an existing Word document
Dim wordDocument As WordDocument = New WordDocument(("Sample.docx"), FormatType.Docx)
'Create an instance of DocToPDFConverter
Dim converter As DocToPDFConverter = New DocToPDFConverter
'Convert Word document into PDF document
Dim pdfDocument As PdfDocument = converter.ConvertToPDF(wordDocument)
'Save the PDF file
pdfDocument.Save("WordtoPDF.pdf")
'Close the instance of document objects
pdfDocument.Close(True)
wordDocument.Close()
'This will open the PDF file so, the result will be seen in default PDF viewer
System.Diagnostics.Process.Start("WordtoPDF.pdf")

 

A complete working sample can be downloaded from WordToPDFSample.zip

By executing the program, you will get the PDF document as follows.

Output document screenshot in WinForms PDF

Take a moment to peruse the documentation for working with document conversion, where you will find other options like Excel, RTF, TIFF, and XPS to PDF conversion.

An online sample link demonstrating the use of Word to PDF conversion.

Refer here to explore the rich set of Syncfusion Essential PDF features.

Note:

Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to link to learn about generating and registering Syncfusion license key in your application to use the components without trail message.

 

See Also:

Convert Word to PDF in UWP

Convert Word to PDF in ASP.NET Core

Convert Word to PDF in Xamarin

 

Conclusion


I hope you enjoyed learning about how to convert Word to PDF using C# and VB.NET in WF application.

You can refer to our .NET PDF  feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our .NET PDF example to understand how to create and manipulate data in the .NET PDF. 

For current customers, you can check out our Document processing libraries from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments
Please sign in to leave a comment
Access denied
Access denied