Convert From One Format to Another

Use Wordize for .NET conversion feature to convert a document from one format to another using C#. Use various Wordize modules to convert DOCX to HTML, DOCX to PDF, Web formats to Word formats, and so on.

Go to Conversion Code Examples

Wordize’s document conversion feature allows developers to easily convert documents from one format to another, ensuring high fidelity and preserving formatting, styles, and content.

With a variety of modules tailored to specific needs, Wordize offers powerful and flexible APIs for working with MS Word documents, web formats, eBooks, PDFs, images, and OpenOffice files.

The following list of modules and formats is currently available:

Conversion ModuleSupported formats
Wordize Core for .NETLoad/Save MS Word document formats (DOC, DOCX, RTF, FlatOpc, XML, TXT, XLSX)
Wordize Web for .NETLoad/Save Web formats (HTML, MHTML, MD, CHM)
Wordize eBook for .NETLoad/Save eBook formats (EPUB, AWZ3, MOBI)
Wordize OpenOffice for .NETLoad/Save open office documents (ODT, OTT)
Wordize PDF Load for .NETLoad PDF documents (PDF)
Wordize Rendering for .NETSave documents to fixed page formats (PDF, XPS, SVG, PS, Image, PostScript, etc.)

How to Work With Conversion Modules

There is a basic Wordize Core for .NET module that allows users to load and save documents in Microsoft Word format. Without purchasing this basic module, none of the other modules work.

If you want to convert to a wider range of formats, you need additional conversion modules:

  • If you want to convert from DOC to DOCX, you only need the basic module Wordize Core for .NET
  • If you need to convert DOCX to HTML, then in addition to Wordize Core for .NET, you will need the module Wordize Web for .NET
  • If you need to convert DOCX to HTML and EPUB, you need the modules Wordize Core for .NET, Wordize Web for .NET, Wordize eBook for .NET
  • And so on

What is Document Conversion?

Conversion is the process of loading a document and then saving it in the target format. You can load a document from a stream or file and also save it to a stream or file.

Wordize simplifies the process of converting your documents. You don’t need to load and save the document separately. You simply use one of the Convert methods with various overloads to perform the conversion in one action.

Find a full list of code examples for document conversion in the Conversion Code Examples section at the bottom of the page. But in the following subsections we will show examples of simple conversions – DOCX to PDF, DOCX to HTML, and DOCX to PNG.

Convert DOCX to PDF

If you want to convert DOCX to PDF, you will need the Wordize Core for .NET and Wordize Rendering for .NET modules and the corresponding licenses.

The following code example shows how to convert DOCX to PDF using the Convert(string, string) method:

string doc = "Document.docx";

Converter.Convert(doc, "ConvertedDocument.pdf");

Convert DOCX to HTML

If you want to convert DOCX to HTML, you will need the Wordize Core for .NET and Wordize Web for .NET modules and the corresponding licenses.

The following code example shows how to convert DOCX to HTML using the Convert(string, string) method:

string doc = "Document.docx";

Converter.Convert(doc, "ConvertedDocument.html");

Convert DOCX to PNG

It is important to note that when converting a multi-page document to an image, there are two options:

  1. When saving to a file, each page will be saved as a separate file.
  2. When saving to a stream, only the first page will be saved. To save all pages, you must use Converter.ConvertToImages.

The following code example shows how to convert DOCX to PNG using the ConvertToImages(string, ImageSaveOptions):

Stream[] pages = Converter.ConvertToImages("Document1.docx", new ImageSaveOptions(SaveFormat.Png));

If you want to convert DOCX to PNG, you will need the Wordize Core for .NET and Wordize Rendering for .NET modules and the corresponding licenses.

Document Conversion Accuracy

The internal Wordize document object model is designed to work mostly with MS Word document formats such as DOC, DOCX, or RTF. Although Wordize supports a wide range of formats, many of them are not native to MS Word. Therefore, please note that converting one document format to another may result in a loss of fidelity.

Different Object Models

Conversion fidelity should be especially taken into account when converting documents whose object models are very different, and it is not always possible to ensure 100% fidelity after converting one model to another. For example, this can be observed when converting HTML-based formats to MS Word formats.

Using Fonts

Conversion fidelity can also be reduced when converting flow-layout formats (where the geometry of objects and their position on the page are not fixed, such as Word formats) to fixed-layout formats (where the geometry of objects and their position on the page are fixed, such as PDF or image formats), because conversion to fixed-page formats requires building a document layout.

For example, Wordize mimics MS Word when building a document page layout. However, to build an accurate document layout, the fonts used in the original document are required. If Wordize cannot find the fonts used in the document, the fonts are substituted. This may result in layout differences due to differences in font metrics. To minimize differences, you can configure font settings globally using Wordize.Settings.DefaultFontSettings:

Wordize.Settings.DefaultFontSettings.SetFontsFolder(@"C:\Fonts", true);

Converting PDF to Other Formats

It is worth noting that Wordize supports PDF as an input document format. PDF documents are fixed-layout format documents, and if a PDF document is converted to a flow-layout document format, Wordize converts the fixed-layout document structure to a flow-layout document object model. Unfortunately, this conversion does not guarantee 100% accuracy either.

On the other hand, converting from PDF to another fixed-layout format does not require transformation of the document model. Therefore, converting PDF to the following formats will provide better performance and accuracy: Pdf, Tiff, Png, Bmp, Jpeg, Gif, Svg, Xps, HtmlFixed, Pcl, OpenXps, WebP, Emf, Eps.

Conversion Code Examples

Wordize provides both a Standard API and a Fluent API, allowing developers to choose the most convenient approach for their needs.

Go to Conversion description

Wordize API

The following code examples show how to convert a document from one format to another, specifying conversion options and using one of the Convert methods.


method Convert(string, string)
string doc = "Document.doc";

Converter.Convert(doc, "ConvertedDocument.1.docx");

method Convert(string, string, SaveFormat)
string doc = "Document.doc";

Converter.Convert(doc, "ConvertedDocument.2.html", SaveFormat.Html);

method Convert(Stream, Stream, SaveFormat)
using var streamIn = File.OpenRead("Document.docx");
using var streamOut = File.Create("ConvertedDocument.3.md");

Converter.Convert(streamIn, streamOut, SaveFormat.md);

method ConvertToImages(string, ImageSaveOptions)
Stream[] pages = Converter.ConvertToImages("Document1.docx", new ImageSaveOptions(SaveFormat.Png));

method ConvertToImages(Stream, ImageSaveOptions)
using var streamIn = File.OpenRead("Document1.docx");

Stream[] pages = Converter.ConvertToImages(streamIn, new ImageSaveOptions(SaveFormat.Png));

Wordize Fluent API

Within the Fluent API, there is a context. ProcessorContext allows you to customize the document conversion process. Specify the following properties to add the context:

  • FontSettings – to ustomize font settings for each document processing operation
  • LayoutOptions – to configure the document layout process
  • IWarningCallback – to receive notification when a font substitution is performed

You can convert documents with or without context.


method to Convert a document from file to a file
Converter.Create()
    .From("DocumentIn.docx")
    .To("DocumentOut.pdf")
    .Execute();

method to Convert a document from file to a file, specifying the output SaveFormat as a parameter or as a SaveOption

The following code example shows how to convert a document to PDF, specifying the output SaveFormat as a parameter:

Converter.Create()
    .From("DocumentIn.docx")
    .To("DocumentOut.pdf", SaveFormat.Pdf)
    .Execute();

The output document format can be specified explicitly, as shown above. Alternatively, you can specify advanced saving options by passing an appropriate SaveOptions instance. The following code example shows how to convert a document to PDF with Ua2 compliance:

Converter.Create()
    .From("DocumentIn.docx")
    .To("DocumentOut.pdf", new PdfSaveOptions() { Compliance = PdfCompliance.PdfUa2 })
    .Execute();

method to Convert a document from a file into multiple output types at the same time
Converter.Create()
    .From("DocumentIn.pdf")
    .To("DocumentOut.xps")
    .To("DocumentOut.tiff")
    .To("DocumentOut.docx")
    .Execute();

method to Convert a document from file to a file, specifying the LoadOptions

Sometimes it is required to specify additional document load options, for example, to convert a password-encrypted document. In this case, simply pass the appropriate LoadOptions:

Converter.Create()
    .From("EncryptedDocument.docx", new LoadOptions() { Password = "1234" })
    .To("DocumentOut.pdf")
    .Execute();

method to Convert a document from file to a file, specifying the LayoutOptions as context
ConverterContext context = new ConverterContext();
context.LayoutOptions.CommentDisplayMode = Layout.CommentDisplayMode.Hide;
context.LayoutOptions.RevisionOptions.ShowRevisionMarks = false;
context.LayoutOptions.RevisionOptions.ShowRevisionBars = false;

Converter.Create(context)
    .From("DocumentIn.docx")
    .To("DocumentOut.pdf")
    .Execute();

method to Convert a document from file to a file, specifying the FontSettings and IWarningCallback as context
ConverterContext context = new ConverterContext();
context.FontSettings = new FontSettings();
context.FontSettings.SetFontsFolder(@"C:\Fonts", true);

Converter.Create(context)
    .From("DocumentIn.docx")
    .To("DocumentOut.pdf")
    .Execute();
ConverterContext context = new ConverterContext();
context.WarningCallback = new FontSubstitutionWarningCallback();

Converter.Create(context)
    .From("DocumentIn.docx")
    .To("DocumentOut.pdf")
    .Execute();

private class FontSubstitutionWarningCallback : IWarningCallback
{
    public void Warning(WarningInfo info)
    {
        if (info.WarningType == WarningType.FontSubstitution)
            Console.WriteLine(info.Description);
    }
}

method to Convert a document from file to a stream, specifying the output SaveFormat
using var streamOut = File.Create("ConvertedDocument.1.Pdf");

Converter.Create()
    .From("DocumentIn.docx")
    .To(streamOut, SaveFormat.Pdf)
    .Execute();

method to Convert a document from file to a list of streams, specifying the output SaveFormat

The result can be saved not only to a file or stream, but also to a list of streams. The latter is useful when saving the result as images, where each page of the document is saved as a separate stream and added to the list. In this case, you can specify multiple output types at the same time.

MemoryStream outStream = new MemoryStream();
List<Stream> outputStreams = new List<Stream>();

Converter.Create()
    .From("DocumentIn.docx")
    .To(outStream, SaveFormat.Odt)
    .To(outputStreams, SaveFormat.Png) // Note: a separate stream is created for each page. The streams disposing is the consumer responsibility.
    .Execute();

method to Convert a document from a stream and seve the result to a stream, specifying the output SaveFormat
using var streamIn = File.OpenRead("Document1.docx");
using var streamOut = File.Create("ConvertedDocument.1.Pdf");

Converter.Create()
    .From(streamIn)
    .To(streamOut, SaveFormat.Pdf)
    .Execute();

method to Convert a document from a file and save the result to an image
List<Stream> outputStreams = new List<Stream>();

Converter.Convert()
    .From("Document1.docx")
    .To(outputStreams, new ImageSaveOptions(SaveFormat.Png)) // Note: a separate stream is created for each page. The streams disposing is the consumer responsibility.
    .Execute();

method to Convert a document from a stream and save the result to an image
using var streamIn = File.OpenRead("Document1.docx");

List<Stream> outputStreams = new List<Stream>();

Converter.Convert()
    .From(streamIn)
    .To(outputStreams, new ImageSaveOptions(SaveFormat.Png)) // Note: a separate stream is created for each page. The streams disposing is the consumer responsibility.
    .Execute();