# HTML and MHTML in .NET

Parse HTML and MHTML safely in .NET and turn web content into PDF, images, Word, Markdown or RTF with one HTML engine, PSWriteOffice and the CLI.

**Packages**

- [OfficeIMO.Html](https://www.nuget.org/packages/OfficeIMO.Html) `dotnet add package OfficeIMO.Html`
- [OfficeIMO.Html.Pdf](https://www.nuget.org/packages/OfficeIMO.Html.Pdf) `dotnet add package OfficeIMO.Html.Pdf`

**Works with**

- .NET
- [PowerShell](/docs/pswriteoffice/install/) `Install-Module PSWriteOffice`
- [CLI](/docs/cli/install/) `dotnet tool install --global OfficeIMO.Tool`

**Target frameworks**

netstandard2.0, net10.0, net472

**APIs**

- [`HtmlConversionDocument`](/api/html/officeimo-html-htmlconversiondocument/)
- [`MhtmlDocument`](/api/mhtml/officeimo-mhtml-mhtmldocument/)
- [`HtmlConversionDocumentOptions`](/api/html/officeimo-html-htmlconversiondocumentoptions/)
- [`HtmlInputTrust`](/api/html/officeimo-html-htmlinputtrust/)

**Cmdlets**

- [`Convert-OfficeDocument`](/api/powershell/convert-officedocument/)
- [`New-OfficeHtmlConversionOptions`](/api/powershell/new-officehtmlconversionoptions/)

**Commands**

- [`officeimo html convert`](/docs/cli/html/)
- [`officeimo html capabilities`](/docs/cli/html/)

**Limits**

The managed renderer handles static HTML and CSS; JavaScript, animation and live browser state are outside this path. [OfficeIMO.Html support matrix](/compatibility/#package-html), [OfficeIMO.Html.Pdf support matrix](/compatibility/#package-html-pdf)

**Verified**

Examples compiled against the source on 2026-11-14

**Data**

- [OfficeIMO.Html API index](/api/html/index.json)
- [OfficeIMO.Html.Pdf API index](/api/html-pdf/index.json)
- [PSWriteOffice command catalog](/data/powershell/commands.json)
- [CLI command catalog](/data/cli/commands.json)
- [Capability catalog (JSON)](/data/capabilities.json)

`OfficeIMO.Html` parses HTML into an `HtmlConversionDocument` with bounded limits, URL policy and base-URI handling. That one parsed document feeds every destination adapter, so Word, Markdown, RTF, PDF and image output agree on how the page was read. Install only the adapter for your destination:

| Destination | Package | Call |
|---|---|---|
| PDF and images (PNG, JPEG, TIFF, WebP, SVG) | `OfficeIMO.Html.Pdf` | `SaveAsPdf`, `ToImage`, `SaveAsImages` |
| Word | `OfficeIMO.Word.Html` | `ToWord` |
| Markdown | `OfficeIMO.Markdown.Html` | `ToMarkdown` |
| RTF | `OfficeIMO.Html.Rtf` | `ToRtf` |
| MHTML archives | `OfficeIMO.Mhtml` | `MhtmlDocument.Load` |
| Search and ingestion | `OfficeIMO.Reader.Html` | Reader handlers |

```sh
dotnet add package OfficeIMO.Html.Pdf
```

## Parse HTML from a string or file

Untrusted input is the default: no local file or network reads, and strict size and depth limits. Mark input as trusted only for your own templates.

### C#

```csharp
using OfficeIMO.Html;

HtmlConversionDocument fromText = HtmlConversionDocument.Parse(
    "<h1>Status</h1><p>Generated by OfficeIMO.</p>");
Console.WriteLine(fromText.NormalizedHtml);

File.WriteAllText("report.html", "<html><body><h1>Report</h1></body></html>");
HtmlConversionDocument fromFile = HtmlConversionDocument.Load("report.html", new HtmlConversionDocumentOptions {
    Trust = HtmlInputTrust.Trusted,
    BaseUri = new Uri(Path.GetFullPath(".") + Path.DirectorySeparatorChar)
});
Console.WriteLine(fromFile.SourceHtml.Length);
```

### PowerShell

```powershell
$document = New-OfficeHtmlConversionOptions -BaseUri (Resolve-Path .\Assets) -NoBodyContentsOnly
Convert-OfficeDocument -Path .\Report.html -To Word -OutputPath .\Report.docx -Options $document
```

## Convert HTML to PDF

### C#

```csharp
using OfficeIMO.Html;
using OfficeIMO.Html.Pdf;

HtmlConversionDocument
    .Parse("<h1>Status</h1><p>All systems normal.</p>")
    .SaveAsPdf("status.pdf");
```

### PowerShell

```powershell
Convert-OfficeDocument -Path .\Report.html -OutputPath .\Report.pdf
```

### CLI

```sh
officeimo html convert report.html --output report.pdf
```

## List what the renderer supports

The capability list is generated from the same catalog the .NET API uses.

### CLI

```sh
officeimo html capabilities --format json
```

<!-- PowerForge markdown source sha256:6A74ED3C166D5CFA25C482CBA14C3FE86A04B9CFE5DA0277BD42ABA039301FA7; title=True -->

<!-- PowerForge markdown artifact sha256:6A454F7DAA4AA79E07FB1DC5EC9A9F68CA844EB3F336F38D5D63D4A32E169E96 -->
