Convert Word to PDF (.NET Framework)
In the following two examples you convert Word to PDF using DynamicPDF Converter for .NET. As the examples illustrate, converting from Word to PDF is straightforward when using DynamicPDF Converter.
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 if advanced options are required, then use the [WordConverter](/docs/dotnet/cete.dynamicpdf.conversion.wordconverter" Word Converter Class") class with WordConversionOptions. The following two examples illustrate.
Steps to Convert DOCX/DOC to PDF
- Use the static Convert method of the Converter class and pass the path to the Word document to convert and the path to the PDF document to create.
Sample Code - C# using Convert()
To convert a Word document to a PDF is straightforward when you use the Converter.Convert method. The following one line of code illustrates.
Converter.Convert("sample.docx", "sample.pdf")
Steps to Convert DOCX/DOC to PDF
- Create a new
WordConversionOptions
object instance and in the constructor indicate that you are not appending to an existing PDF. - Create a new
WordConverter
object instance and in the constructor specify the path to the Word file and the WordConversionOptions instance. - Set the top, bottom, left, and right margins.
- Call the
Convert
method on the WordConverter instance and specify the path to the PDF file to create.
Sample Code - C#
WordConversionOptions options = new WordConversionOptions(false);
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("sample.pdf");
Getting Started
NuGet Package
DynamicPDF Converter is available on NuGet and is part of the ceTe.DynamicPDF.Converter.NET
package. The easiest way to install the package is by using the Visual Studio Package manager. You can also download directly from NuGet.
GitHub Example Project
Clone or view the example project at GitHub.
DynamicPDF Converter Information
More information on DynamicPDF Converter can be found at the following website.