Convert Word to PDF
Easily convert a Microsoft Word file to a PDF document using DynamicPDF Converter for .NET. The following C# examples show you how.
Watch the Video
How to Convert Word to PDF
The easiest way to convert a Word (docx or doc) file to a PDF is by calling the static Convert method of the Converter class. But DynamicPDF Converter for .NEt also provides the WordConverter
class and WordConversionOptions
classe to customize conversion.
Steps to Convert DOCX/DOC to PDF (using static Convert method)
- Use the static
Convert
method of theConverter
class and pass the path to the Word document to convert and the path to the PDF document to create.
Sample Code - C#
Converter.Convert("sample.docx", "output.pdf")
Steps to Convert DOCX/DOC to PDF (using WordConverter)
- Create a new
WordConverter
object instance and in the constructor specify the path to the Word file. - Add the
Convert
method on theWordConverter
instance and specify the path to the PDF file to create.
Sample Code - C#
WordConverter wordDocConverter = new WordConverter(Program.GetResourcePath("sample.doc");
wordDocConverter.Convert("output.pdf");
Steps to Convert DOCX/DOC to PDF (using WordConverter and WordConversionOptions)
- Create a new
WordConversionOptions
object instance. - Set the top, bottom, left, and right margins.
- Create a new
WordConverter
object instance and in the constructor specify the path to the Word file and theWordConversionOptions
instance. - Add the
Convert
method on theWordConverter
instance and specify the path to the PDF file to create.
Sample Code - C#
WordConversionOptions options = new WordConversionOptions();
options.Author = "John Doe";
options.TopMargin = 144;
options.BottomMargin = 72;
options.LeftMargin = 72;
options.RightMargin = 72;
WordConverter wordDocConverter = new WordConverter("sample.doc", options);
wordDocConverter.Convert("output.pdf");
GitHub Project
Examples are provided in C# and VB.NET. Clone or view the example project at GitHub.
- C# -WordFileConversion.cs
- VB.NET - WordFileConversion.vb
Getting Started
Get started easily by installing DynamicPDF Converter for .NET through NuGet or manually. Then, refer to the documentation for more information on using and purchasing.
NuGet Package
The easiest way to install DynamicPDF Converter for .NET is by obtaining the NuGet package using Visual Studio's Package Manager. You can also obtain the NuGet package by downloading it directly. Refer to the installation documentation for more information.
NuGet Package ID: ceTe.DynamicPDF.Converter.NET
More Information on Word Conversion
- Simple Conversion
- Converting Word Documents to PDFs
- Chapter 6, Converting Microsoft Word, in the book DynamicPDF Converter for .NET by Example available on GitHub.
DynamicPDF Converter Information
DynamicPDF Converter for .NET allows any .NET developer to dynamically convert many common file formats to PDF documents in real-time. It supports converting over 50 file types to PDF, including HTML and MS Office formats. The software supports events, enabling developers to easily and accurately handle both successful and failed conversions. It is intuitive and seamlessly integrates with all our DynamicPDF products. With a Free Evaluation Edition to try, why not start using DynamicPDF Converter Today!