# Convert HTML to Word in C#

### Overview

[Overview](https://www.nutrient.io/guides/dotnet/conversion/to-office.md)

### PDF to DOCX

[PDF to DOCX](https://www.nutrient.io/guides/dotnet/conversion/pdf-to-word.md)

### PDF to XLSX

[PDF to XLSX](https://www.nutrient.io/guides/dotnet/conversion/pdf-to-excel.md)

### PDF to PPTX

[PDF to PPTX](https://www.nutrient.io/guides/dotnet/conversion/pdf-to-powerpoint.md)

### HTML to DOCX

[HTML to DOCX](https://www.nutrient.io/guides/dotnet/conversion/html-to-word.md)

### RTF to DOCX

[RTF to DOCX](https://www.nutrient.io/guides/dotnet/conversion/rtf-to-docx.md)

### Any File to Office

[Any File to Office](https://www.nutrient.io/guides/dotnet/conversion/any-file-to-office.md)

Nutrient.NET SDK (formerly GdPicture.NET) includes the ability to convert any supported file type into Word.

To save an HTML file to a Word document (DOCX), first use the [`SaveAsPDF` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14~GdPicture14.GdPictureDocumentConverter~SaveAsPDF.html) of the [`GdPictureDocumentConverter` class](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14~GdPicture14.GdPictureDocumentConverter.html) to convert it to PDF. Then use the [`SaveAsDOCX` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14~GdPicture14.GdPictureDocumentConverter~SaveAsDOCX.html) to convert it to a DOCX.

The `SaveAsPDF` method uses the following parameters:

- `Stream`, or the overload `FilePath` — A stream object where the current document is saved as a DOCX file. This stream object must be initialized before it can be sent into this method, and it should stay open for subsequent use. If the output stream isn’t open for both reading and writing, the method will fail, returning the `GdPictureStatus.InvalidParameter` status, which is the file path where the converted file will be saved. If the specified file already exists, it’ll be overwritten. You have to specify a full file path, including the file extension.

- `Conformance` — A member of the [`PdfConformance` enumeration](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14~GdPicture14.PdfConformance.html). This specifies the required conformance to the PDF or PDF/A standard of the saved PDF document. You can use the value of `PdfConformance.PDF` to save the file as a common PDF document.

The `SaveAsDOCX` method uses the following parameters:

- `Stream`, or the overload `FilePath`

Note that the output stream should be open for both reading and writing and closed/disposed of by the user once processing is complete using the [`CloseDocument` method](/api/gdpicture/GdPicture.NET.14~GdPicture14.GdPictureDocumentConverter~CloseDocument.html).

## How to convert HTML to DOCX

1. Create a `GdPictureDocumentConverter` object.

2. Convert the source HTML file to PDF with [`GdPictureDocumentConverter.SaveAsPDF(Stream, PdfConformance)`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14~GdPicture14.GdPictureDocumentConverter~SaveAsPDF.html). Recommended: Specify the source document format with a member of the [`DocumentFormat` enumeration](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14~GdPicture14.DocumentFormat.html).

3. Load the newly generated PDF file by passing its path to the [`LoadFromFile` method](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14~GdPicture14.GdPictureDocumentConverter~LoadFromFile.html) (this method only supports PDF documents).

4. Save the PDF file as a DOCX using `SaveAsDOCX`.

The following example converts and saves an HTML document to a DOCX file (it can also be saved as a stream):

### C#

```csharp

using GdPictureDocumentConverter converter = new();

// Set the text and document properties to be used for the resulting file.
converter.HtmlPageHeight = 842; // A3 page size
converter.HtmlPageWidth = 1191;  // A3 page size
converter.HtmlPageMarginTop = 10;
converter.HtmlPageMarginBottom = 10;
converter.HtmlPageMarginLeft = 10;
converter.HtmlPageMarginRight = 10;

using Stream inputStream = File.Open(@"input.html", System.IO.FileMode.Open);
using Stream outputStream = new MemoryStream();

GdPictureStatus status = converter.ConvertToPDF(inputStream, GdPicture14.DocumentFormat.DocumentFormatHTML, outputStream, PdfConformance.PDF1_5);
if (status!= GdPictureStatus.OK)
{
    throw new Exception(status.ToString());
}

status = converter.LoadFromStream(outputStream);
if (status!= GdPictureStatus.OK)
{
    throw new Exception(status.ToString());
}

status = converter.SaveAsDOCX("output.docx");
if (status!= GdPictureStatus.OK)
{
    throw new Exception(status.ToString());
}

Console.WriteLine("The input document has been converted to a docx file");

```

#### See also

- [`DocxImageQuality Property`](/api/gdpicture/GdPicture.NET.14~GdPicture14.GdPictureDocumentConverter~DocxImageQuality.html)

- [`GdPictureDocumentConverter Class`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14~GdPicture14.GdPictureDocumentConverter.html)

- [`GdPictureDocumentConverter Members`](/api/gdpicture/GdPicture.NET.14~GdPicture14.GdPictureDocumentConverter_members.html)

- [`CloseDocument Method`](/api/gdpicture/GdPicture.NET.14~GdPicture14.GdPictureDocumentConverter~CloseDocument.html)

- [`RasterizationDPI Property`](/api/gdpicture/GdPicture.NET.14~GdPicture14.GdPictureDocumentConverter~RasterizationDPI.html)

- [`HtmlEmulationType Property`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureDocumentConverter~HtmlEmulationType.html)

- [`HtmlPageHeight Property`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureDocumentConverter~HtmlPageHeight.html)

- [`HtmlPageMarginBottom Property`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureDocumentConverter~HtmlPageMarginBottom.html)

- [`HtmlPageMarginLeft Property`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureDocumentConverter~HtmlPageMarginLeft.html)

- [`HtmlPageMarginRight Property`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureDocumentConverter~HtmlPageMarginRight.html)

- [`HtmlPageMarginTop Property`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureDocumentConverter~HtmlPageMarginTop.html)

- [`HtmlPageWidth Property`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureDocumentConverter~HtmlPageWidth.html)

- [`HtmlPreferCSSPageSize Property`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureDocumentConverter~HtmlPreferCSSPageSize.html)

- [`HtmlPreferOnePage Property`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureDocumentConverter~HtmlPreferOnePage.html)

#### Related topics

- [Load a file](/guides/dotnet/load-a-file.md)

- [Save a file](/guides/dotnet/save-a-file.md)

## Optional HTML configuration properties

Optionally, configure the conversion with the following properties of the `GdPictureDocumentConverter` object:

- [`HtmlEmulationType`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureDocumentConverter~HtmlEmulationType.html)

- [`HtmlPageHeight`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureDocumentConverter~HtmlPageHeight.html)

- [`HtmlPageMarginBottom`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureDocumentConverter~HtmlPageMarginBottom.html)

- [`HtmlPageMarginLeft`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureDocumentConverter~HtmlPageMarginLeft.html)

- [`HtmlPageMarginRight`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureDocumentConverter~HtmlPageMarginRight.html)

- [`HtmlPageMarginTop`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureDocumentConverter~HtmlPageMarginTop.html)

- [`HtmlPageWidth`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureDocumentConverter~HtmlPageWidth.html)

- [`HtmlPreferCSSPageSize`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureDocumentConverter~HtmlPreferCSSPageSize.html)

- [`HtmlPreferOnePage`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureDocumentConverter~HtmlPreferOnePage.html)











## Optional PDF configuration properties

Optionally, configure the conversion with the following properties of the `GdPictureDocumentConverter` object:

- [`PdfBitonalImageCompression`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureDocumentConverter~PdfBitonalImageCompression.html) is a member of the `PdfCompression` enumeration that specifies the compression scheme used for bitonal images in the output PDF file.

- [`PdfColorImageCompression`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureDocumentConverter~PdfColorImageCompression.html) is a member of the `PdfCompression` enumeration that specifies the compression scheme used for color images in the output PDF file.

- [`PdfEnableColorDetection`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureDocumentConverter~PdfEnableColorDetection.html) is a Boolean value that specifies whether to use automatic color detection during the conversion that preserves image quality and reduces the output file size.

- [`PdfEnableLinearization`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureDocumentConverter~PdfEnableLinearization.html) is a Boolean value that specifies whether to linearize the output PDF to enable Fast Web View mode.

- [`PdfImageQuality`](https://www.nutrient.io/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureDocumentConverter~PdfImageQuality.html) is an integer from 0 to 100 that specifies the image quality in the output PDF file.

The example below creates a PDF document from an HTML file with a custom configuration:

### C#

```csharp

using GdPictureDocumentConverter gdpictureDocumentConverter = new GdPictureDocumentConverter();
// Load the source document.
gdpictureDocumentConverter.LoadFromFile(@"C:\temp\source.html", GdPicture14.DocumentFormat.DocumentFormatHTML);
// Configure the conversion.
gdpictureDocumentConverter.PdfColorImageCompression = PdfCompression.PdfCompressionJPEG;
gdpictureDocumentConverter.PdfImageQuality = 50;
// Save the output in a new PDF document.
gdpictureDocumentConverter.SaveAsPDF(@"C:\temp\output.pdf");

```

### VB.NET

```vb

Using gdpictureDocumentConverter As GdPictureDocumentConverter = New GdPictureDocumentConverter()
    ' Load the source document.
    gdpictureDocumentConverter.LoadFromFile("C:\temp\source.html", GdPicture14.DocumentFormat.DocumentFormatHTML);
    ' Configure the conversion.
    gdpictureDocumentConverter.PdfColorImageCompression = PdfCompression.PdfCompressionJPEG
    gdpictureDocumentConverter.PdfImageQuality = 50
    ' Save the output in a new PDF document.
    gdpictureDocumentConverter.SaveAsPDF("C:\temp\output.pdf")
End Using

```

#### Used methods and properties

- [`LoadFromFile`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureDocumentConverter~LoadFromFile.html)

- [`PdfColorImageCompression`]

- [`PdfImageQuality`]

- [`SaveAsPDF`](/api/gdpicture/GdPicture.NET.14.API~GdPicture14.GdPictureDocumentConverter~SaveAsPDF.html)

#### Related topics

- [Load a file](/guides/dotnet/load-a-file.md)

- [Save a file](/guides/dotnet/save-a-file.md)
---

## Related pages

- [Convert to MS Office from any file in C#](/guides/dotnet/conversion/any-file-to-office.md)
- [Convert emails (MSG/EML) to PDF in C#](/guides/dotnet/conversion/email-to-pdf.md)
- [Convert bitmap (BMP) to PDF in C#](/guides/dotnet/conversion/bmp-to-pdf.md)
- [Convert any image to PDF in C#](/guides/dotnet/conversion/any-image-to-pdf.md)
- [Convert HTML to PDF using C# and .NET](/guides/dotnet/conversion/html-to-pdf.md)
- [Convert DWG or DXF to PDF in C#](/guides/dotnet/conversion/cad-to-pdf.md)
- [Embed a font in a Word document](/guides/dotnet/conversion/embed-font-in-word-document.md)
- [Convert files to PDF in C# .NET](/guides/dotnet/conversion.md)
- [Converting a document from Markdown to PDF format](/guides/dotnet/conversion/markdown-to-pdf.md)
- [Convert Excel to PDF in C#](/guides/dotnet/conversion/excel-to-pdf.md)
- [Convert images to PDFs in C#](/guides/dotnet/conversion/image-to-pdf.md)
- [Convert JPG to PDF in C#](/guides/dotnet/conversion/jpg-to-pdf.md)
- [Convert PDF to Excel in C#](/guides/dotnet/conversion/pdf-to-excel.md)
- [Merge and combine multiple files into a PDF in C#](/guides/dotnet/conversion/merge-to-pdf.md)
- [Convert PDF to bitmap (BMP) in C#](/guides/dotnet/conversion/pdf-to-bmp.md)
- [Convert PDF to JPG in C#](/guides/dotnet/conversion/pdf-to-jpg.md)
- [Convert images to PDFs in C#](/guides/dotnet/conversion/pdf-to-image.md)
- [Convert MS Office files to PDFs in C#](/guides/dotnet/conversion/office-to-pdf.md)
- [Converting a document from PDF to Markdown format](/guides/dotnet/conversion/pdf-to-markdown.md)
- [Convert PDF to PDF/UA](/guides/dotnet/conversion/pdf-to-pdf-ua.md)
- [Convert PDF to other images in C#](/guides/dotnet/conversion/pdf-to-other-image.md)
- [Convert PDF to PDF/A](/guides/dotnet/conversion/pdf-to-pdfa.md)
- [Convert PDF to PNG in C#](/guides/dotnet/conversion/pdf-to-png.md)
- [Convert PDF to PowerPoint in C#](/guides/dotnet/conversion/pdf-to-powerpoint.md)
- [Convert PDF to Word in C#](/guides/dotnet/conversion/pdf-to-word.md)
- [Convert PDF to TIFF in C#](/guides/dotnet/conversion/pdf-to-tiff.md)
- [Convert PDF to SVG in C#](/guides/dotnet/conversion/pdf-to-svg.md)
- [Convert PowerPoint to PDF in C#](/guides/dotnet/conversion/powerpoint-to-pdf.md)
- [Convert RTF to Word in C#](/guides/dotnet/conversion/rtf-to-docx.md)
- [Convert PNG to PDF in C#](/guides/dotnet/conversion/png-to-pdf.md)
- [Convert SVG to PDF in C#](/guides/dotnet/conversion/svg-to-pdf.md)
- [Convert RTF to PDF in C#](/guides/dotnet/conversion/rtf-to-pdf.md)
- [Convert text to PDF in C#](/guides/dotnet/conversion/text-to-pdf.md)
- [Convert to Word, Excel, or PowerPoint in C#](/guides/dotnet/conversion/to-office.md)
- [Convert TIFF to PDF in C#](/guides/dotnet/conversion/tiff-to-pdf.md)
- [Convert Word to PDF in C#](/guides/dotnet/conversion/word-to-pdf.md)

