Load WordProcessing document with options

GroupDocs.Conversion provides WordProcessingLoadOptions to give you control over how the source Microsoft Word document will be converted. The following options could be set:

OptionDescription
FormatThe document type is auto-detected during loading, however, you can specify explicitly the type of the source WordProcessing document. Available options are: Doc, Docm, Docx, Dot, Dotm, Dotx, Rtf, Odt, Ott, Mobi, Txt
AutoFontSubstitution If false, GroupDocs.Conversion uses the DefaultFont for the substitution of missing fonts. If true, GroupDocs.Conversion evaluates all the related fields in FontInfo (Panose, Sig etc) for the missing font and finds the closest match among the available font sources.
BookmarkOptionsSpecifies options for handling bookmarks.
DefaultFontSpecifies the font to use if a document font is missing.
EmbedTrueTypeFontsSpecifies whether to embed true type fonts in the output document. Default is false.
FontSubstitutesSubstitute specific fonts from the source document.
HideComments Specifies that comments from the source document should be hidden in the converted document.
HideWordTrackedChanges Specifies that tracked changes should not be included in the converted document.
KeepDateFieldOriginalValue Specifies whether to keep the original values of date fields. Default is false.
Password  A password to unlock the protected document.
PreserveFormFields Specifies whether to preserve Microsoft Word form fields as form fields in PDF or convert them to text. Default is false.
SkipExternalResourcesIf enabled, the external resources (except for those listed in WhitelistedResources) will not be loaded during the conversion.
UpdateFields Specifies whether to update fields after loading. Default is false.
UpdatePageLayout Specifies whether to update page layout after loading. Default is false.
UseTextShaper Specifies whether to use a text shaper for better kerning display. Default is false.
WhitelistedResourcesSpecifies which external resources will be loaded even when the loading of other external resources is restricted.
Note: that the font substitution mechanism will override the DefaultFont in cases when FontInfo for the missing font is available in the document.

Hide comments

Microsoft Word provides the “Comment” feature that allows multiple authors or reviewers to discuss a document when they are not working with it simultaneously. All added comments are displayed in an area to the right of the document text. After the DOCX document with comments is converted to another format, the Comments pane is also present in a resultant document. If it’s required to hide comments in a converted document programmatically, you can use the following code sample to do this with a couple of lines of C# code:

With v24.10 and later:

Func<LoadContext, LoadOptions> getLoadOptions = loadContext => new WordProcessingLoadOptions
{
    HideComments = true
};
using (Converter converter = new Converter("sample.docx", getLoadOptions))
{
    PdfConvertOptions options = new PdfConvertOptions();
    converter.Convert("converted.pdf", options);
}

Before v24.10:

Func<LoadOptions> getLoadOptions = () => new WordProcessingLoadOptions
{
    HideComments = true
};
using (Converter converter = new Converter("sample.docx", getLoadOptions))
{
    PdfConvertOptions options = new PdfConvertOptions();
    converter.Convert("converted.pdf", options);
}

Hide tracked changes

Track Changes is another feature of Microsoft Word that provides a handy way to collaborate during document proofreading and review - it’s like you’re marking errors with a pen and making some notes in the margins. All changes made by coworkers are highlighted and may be rejected or accepted and become permanent. By default, the Track Changes panel will also be displayed when converting a DOCX document to another format, however, there is an option to hide it completely using GroupDocs.Conversion for .NET API. 

The following code snippet shows how to convert a DOCX document to PDF and hide tracked changes pane:

With v24.10 and later:

Func<LoadContext, LoadOptions> getLoadOptions = loadContext => new WordProcessingLoadOptions
{
    HideWordTrackedChanges = true
};
using (Converter converter = new Converter("sample.docx", getLoadOptions))
{
    PdfConvertOptions options = new PdfConvertOptions();
    converter.Convert("converted.pdf", options);
}

Before v24.10:

Func<LoadOptions> getLoadOptions = () => new WordProcessingLoadOptions
{
    HideWordTrackedChanges = true
};
using (Converter converter = new Converter("sample.docx", getLoadOptions))
{
    PdfConvertOptions options = new PdfConvertOptions();
    converter.Convert("converted.pdf", options);
}

Specify font substitution

Microsoft Word document content is often formatted with different fonts like Arial, Calibri, Times New Roman etc., and these fonts are usually stored at the computer where the document is originally created or edited. Sometimes it happens that during DOCX document conversion to another format, some fonts used by a particular document are not present on the computer where conversion is performed. So the resulting converted document may look too different from the original file.

Of course GroupDocs.Conversion for .NET will try to select the most appropriate font substitution from available font sources and fonts embedded in the original document, but you can also specify font substitution explicitly. For doing this it is just needed to call the Create method of FontSubstitute class and provide names for original and substitute fonts.

The following code snippet shows how to convert a DOCX document with font substitution for missing fonts:

With v24.10 and later:

Func<LoadContext, LoadOptions> getLoadOptions = loadContext => new WordProcessingLoadOptions
{
    AutoFontSubstitution = false,
	DefaultFont = "Helvetica",
    FontSubstitutes = new List<FontSubstitute>
    {
        FontSubstitute.Create("Tahoma", "Arial"),
        FontSubstitute.Create("Times New Roman", "Arial"),
    }
};
using (Converter converter = new Converter("sample.docx", getLoadOptions))
{
    PdfConvertOptions options = new PdfConvertOptions();
    converter.Convert("converted.pdf", options);
}

Before v24.10:

Func<LoadOptions> getLoadOptions = () => new WordProcessingLoadOptions
{
    AutoFontSubstitution = false,
	DefaultFont = "Helvetica",
    FontSubstitutes = new List<FontSubstitute>
    {
        FontSubstitute.Create("Tahoma", "Arial"),
        FontSubstitute.Create("Times New Roman", "Arial"),
    }
};
using (Converter converter = new Converter("sample.docx", getLoadOptions))
{
    PdfConvertOptions options = new PdfConvertOptions();
    converter.Convert("converted.pdf", options);
}

Skip loading of external resources

In the context of word-processing documents, external resources refer to any elements, materials, or data that are not directly embedded within the document itself but are referenced or linked to enhance the document’s content or functionality. These external resources can take various forms and are often used to supplement the text and improve the overall quality and richness of the document. Common external resources include images and graphics, tables and spreadsheets, audio and video, fonts, styles, data sources, mathematical equations and so on.

In some cases, you may want to skip loading all or just some of the external resources during the conversion. For example, when these resources become unavailable. Read the Skip loading of external resources article to learn how to do this with GroupDocs.Conversion for .NET.