TL;DR: Learn to create a fillable PDF from a Word document in C# using the .NET Word Library, enabling form fields, dropdowns, checkboxes, and other interactive elements to collect user input.
Fillable PDFs streamline data collection by allowing users to enter and submit information digitally, eliminating the hassle of paper-based forms. Businesses and professionals can quickly share and process these forms, improving efficiency.
With the Syncfusion .NET Word Library (DocIO), we can easily create, edit, and manipulate Word documents programmatically—without relying on Microsoft Office or interop dependencies. This blog explores how to convert Word documents with form fields into fillable PDFs using the .NET Word Library, enabling seamless digital form creation.
Create a template Word document with form fields
To create a structured Word template for conversion into a fillable PDF, we need to include some essential form fields:
- Checkboxes – For multiple-choice selections.
- Dropdowns – To offer predefined choices.
- Text Fields – To collect user input like name and address.
You can create a template Word document using our .NET Word Library (DocIO) programmatically or design it visually using a Word editor. A Word editor helps format and arrange form fields for a structured layout before converting it into a fillable PDF using DocIO.
Note: For more details, refer to the .NET Word Library getting started documentation.
Getting started
Step 1: ** First, create a new C# .NET Core **Console App in Visual Studio.
Step 2: Then, install the Syncfusion.DocIORenderer.Net.Core NuGet package as a reference to the app from NuGet Gallery. Step 3: Now, include the following namespaces in the Program.cs file.
using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;
using Syncfusion.DocIORenderer;
using Syncfusion.Pdf;
Now, the project is ready! Let’s write the code to convert a Word document with form fields into a fillable PDF while preserving the form fields as editable using the PreserveFormFields API.
// Open the Word document as a file stream.
using (FileStream fileStream = new FileStream(Path.GetFullPath("Template.docx"), FileMode.Open))
{
// Load an existing Word document.
using (WordDocument wordDocument = new WordDocument(fileStream, Syncfusion.DocIO.FormatType.Automatic))
{
// Create an instance of DocIORenderer.
using (DocIORenderer renderer = new DocIORenderer())
{
// Enable preserving form fields as editable in the PDF.
renderer.Settings.PreserveFormFields = true;
// Convert the Word document to a PDF.
using (PdfDocument pdfDocument = renderer.ConvertToPDF(wordDocument))
{
// Save the PDF document to a file stream.
using (FileStream outputStream = new FileStream(Path.GetFullPath("Output.pdf"), FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite))
{
pdfDocument.Save(outputStream);
}
}
}
}
}
By executing this code example, we will get the output as shown in the following image.
GitHub reference
You can also find all the examples for creating a fillable PDF from a Word document using our .NET Word Library on this GitHub repository.
Conclusion
Thanks for reading! Syncfusion .NET Word Library offers customizable settings to fine-tune the Word to PDF conversion process, allowing you to optimize performance, enhance accessibility, and preserve document fidelity across platforms. Whether you’re working with Word documents on any .NET platform, the Word to PDF converter simplifies the process for .NET developers.
Take a moment to peruse the Word to PDF conversion documentation, where you can find other options and features, all with code examples.
Are you already a Syncfusion user? You can download the product setup here. If you’re not yet a Syncfusion user, you can download a 30-day free trial.
If you have questions, contact us through our support forum, support portal, or feedback portal. We are always happy to assist you!
Top comments (0)