Convert Word document to PDF in Windows Forms
23 Jul 202610 minutes to read
Syncfusion® DocIO is a .NET Word library used to create, read, edit, and convert Word documents programmatically without Microsoft Word or interop dependencies. Using this library, you can convert a Word document to PDF in Windows Forms.
Steps to convert Word document to PDF in Windows Forms
Prerequisites:
- Visual Studio 2022.
- Install the .NET desktop development workload.
- .NET Framework 4.6.2 or later (target framework when creating the project).
- An
Input.docxfile placed in aDatafolder at the project root, with Copy to Output Directory set to Copy always.
Step 1: Create a new Windows Forms application project.

Step 2: Install Syncfusion.DocToPdfConverter.WinForms NuGet package as a reference to your Windows Forms application from the NuGet.org.

NOTE
Starting with v16.2.0.x, if you reference Syncfusion® assemblies from trial setup or from the NuGet feed, you also have to add “Syncfusion.Licensing” assembly reference and include a license key in your projects. Please refer to this link to learn how to register the Syncfusion® license key in your application to use our components.
Step 3: Include the following namespaces in the Form1.Designer.cs file.
using System;
using System.IO;
using System.Windows.Forms;
using Syncfusion.DocIO.DLS;
using Syncfusion.DocIO;
using Syncfusion.DocToPDFConverter;
using Syncfusion.Pdf;Step 4: Add a new button in Form1.Designer.cs to create Word file as follows.
private Button btnConvert;
private Label label;
private void InitializeComponent()
{
label = new Label();
btnConvert = new Button();
//Label
label.Location = new System.Drawing.Point(0, 40);
label.Size = new System.Drawing.Size(426, 35);
label.Text = "Click the button to convert a Word document to PDF using Essential DocIO. The resulting PDF can be viewed with any PDF viewer such as Adobe Acrobat.";
label.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//Button
btnConvert.Location = new System.Drawing.Point(180, 110);
btnConvert.Size = new System.Drawing.Size(85, 36);
btnConvert.Text = "Convert Word document to PDF";
btnConvert.Click += new EventHandler(btnConvert_Click);
//Form setup
ClientSize = new System.Drawing.Size(450, 150);
Controls.Add(label);
Controls.Add(btnConvert);
Text = "Convert Word document to PDF";
}
//Event handler stub - implementation provided in Step 5.
private void btnConvert_Click(object sender, EventArgs e)
{
}Step 5: Add the following code in btnConvert_Click to convert Word document to PDF with simple text.
//Load the existing Word document. The path is resolved relative to the output directory
string inputPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\Data\Input.docx");
string outputPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\Sample.pdf");
using (WordDocument document = new WordDocument(Path.GetFullPath(inputPath), FormatType.Docx))
{
//Instantiation of DocToPDFConverter for Word to PDF conversion
using (DocToPDFConverter converter = new DocToPDFConverter())
{
//Converts Word document to PDF
using (PdfDocument pdfDocument = converter.ConvertToPDF(document))
{
//Saves the PDF document
pdfDocument.Save(Path.GetFullPath(outputPath));
}
}
}Step 6: Build the project.
Click on Build → Build Solution or press Ctrl+Shift+B to build the project.
Step 7: Run the project.
Click the Start button (green arrow) or press F5 to run the app.
You can download a complete working sample from GitHub.
By executing the program, you will get the PDF document as follows.

Prerequisites:
- JetBrains Rider (latest stable version).
- Install the .NET Framework Developer Pack (4.6.2 or later).
- An
Input.docxfile placed in aDatafolder at the project root, with Copy to Output Directory set to Copy always.
Step 1: Open JetBrains Rider and create a new Windows Forms Application project.
- Launch JetBrains Rider.
- Click New Solution on the welcome screen.

- In the New Solution dialog, select Project Type as Desktop.
- Enter a project name and specify the location.
- Select the target framework as Full Framework and choose .NET Framework 4.6.2 or later.
- Select Template as Windows Forms App.
- Click create.

Step 2: Install the NuGet package from NuGet.org.
- Click the NuGet icon in the Rider toolbar and type Syncfusion.DocToPdfConverter.WinForms in the search bar.
- Ensure that nuget.org is selected as the package source.
- Select the latest Syncfusion.DocToPdfConverter.WinForms NuGet package from the list.
- Click the + (Add) button to add the package.

- Click the Install button to complete the installation.

NOTE
Starting with v16.2.0.x, if you reference Syncfusion® assemblies from trial setup or from the NuGet feed, you also have to add “Syncfusion.Licensing” assembly reference and include a license key in your projects. Please refer to this link to learn how to register the Syncfusion® license key in your application to use our components.
Step 3: Include the following namespaces in the Form1.cs (or Form1.Designer.cs) file.
using System;
using System.IO;
using System.Windows.Forms;
using Syncfusion.DocIO.DLS;
using Syncfusion.DocIO;
using Syncfusion.DocToPDFConverter;
using Syncfusion.Pdf;Step 4: Add a new button in Form1.Designer.cs to create Word file as follows.
private Button btnConvert;
private Label label;
private void InitializeComponent()
{
label = new Label();
btnConvert = new Button();
//Label
label.Location = new System.Drawing.Point(0, 40);
label.Size = new System.Drawing.Size(426, 35);
label.Text = "Click the button to convert a Word document to PDF using Essential DocIO. The resulting PDF can be viewed with any PDF viewer such as Adobe Acrobat.";
label.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//Button
btnConvert.Location = new System.Drawing.Point(180, 110);
btnConvert.Size = new System.Drawing.Size(85, 36);
btnConvert.Text = "Convert Word document to PDF";
btnConvert.Click += new EventHandler(btnConvert_Click);
//Form setup
ClientSize = new System.Drawing.Size(450, 150);
Controls.Add(label);
Controls.Add(btnConvert);
Text = "Convert Word document to PDF";
}Step 5: Add the following code in btnConvert_Click to convert Word document to PDF with simple text.
//Load the existing Word document. The path is resolved relative to the output directory
//(e.g., bin\Debug\Data\Input.docx) since Copy to Output Directory is set to "Copy always".
string inputPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\Data\Input.docx");
string outputPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\Sample.pdf");
using (WordDocument document = new WordDocument(Path.GetFullPath(inputPath), FormatType.Docx))
{
//Instantiation of DocToPDFConverter for Word to PDF conversion
using (DocToPDFConverter converter = new DocToPDFConverter())
{
//Converts Word document to PDF
using (PdfDocument pdfDocument = converter.ConvertToPDF(document))
{
//Saves the PDF document
pdfDocument.Save(Path.GetFullPath(outputPath));
}
}
}NOTE
Troubleshooting tip: If the sample throws
FileNotFoundExceptionforInput.docx, confirm the file is present in theDatafolder and that Copy to Output Directory is set to Copy always. For advanced conversion options, see Word to PDF settings.
Step 6: Build the project.
Click the Build button in the toolbar or press Ctrl+Shift+B to build the project.
Step 7: Run the project.
Click the Run button (green arrow) in the toolbar or press F5 to run the app.
You can download a complete working sample from GitHub.
By executing the program, you will get the PDF document as follows.

Looking for the full .NET Word Library overview, features, pricing, and documentation? Visit the .NET Word Library page.
An online sample link to convert Word document to PDF in ASP.NET Core.