Enum HtmlVersion

Enum HtmlVersion

Namespace: Aspose.Words.Saving
Assembly: Aspose.Words.dll (25.12.0)

Indicates the version of HTML is used when saving the document to Aspose.Words.SaveFormat.Html and Aspose.Words.SaveFormat.Mhtml formats.

public enum HtmlVersion

Fields

Html5 = 1

Saves the document in compliance with the HTML 5 standard.

Xhtml = 0

Saves the document in compliance with the XHTML 1.0 Transitional standard.

Aspose.Words aims to output XHTML according to the XHTML 1.0 Transitional standard, but the output will not always validate against the DTD. Some structures inside a Microsoft Word document are hard or impossible to map to a document that will validate against the XHTML schema. For example, XHTML does not allow nested lists (UL cannot be nested inside another UL element), but in Microsoft Word document multilevel lists occur quite often.

Examples

Shows how to display a DOCTYPE heading when converting documents to the Xhtml 1.0 transitional standard.

Document doc = new Document();
                                                                                                                   DocumentBuilder builder = new DocumentBuilder(doc);

                                                                                                                   builder.Writeln("Hello world!");

                                                                                                                   HtmlSaveOptions options = new HtmlSaveOptions(SaveFormat.Html)
                                                                                                                   {
                                                                                                                       HtmlVersion = HtmlVersion.Xhtml,
                                                                                                                       ExportXhtmlTransitional = showDoctypeDeclaration,
                                                                                                                       PrettyFormat = true
                                                                                                                   };

                                                                                                                   doc.Save(ArtifactsDir + "HtmlSaveOptions.ExportXhtmlTransitional.html", options);

                                                                                                                   // Our document will only contain a DOCTYPE declaration heading if we have set the "ExportXhtmlTransitional" flag to "true".
                                                                                                                   string outDocContents = File.ReadAllText(ArtifactsDir + "HtmlSaveOptions.ExportXhtmlTransitional.html");
                                                                                                                   string newLine = Environment.NewLine;

                                                                                                                   if (showDoctypeDeclaration)
                                                                                                                       Assert.That(outDocContents.Contains(
                                                                                                                           $"<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>{newLine}" +
                                                                                                                           $"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">{newLine}" +
                                                                                                                           "<html xmlns=\"http://www.w3.org/1999/xhtml\">"), Is.True);
                                                                                                                   else
                                                                                                                       Assert.That(outDocContents.Contains("<html>"), Is.True);

Shows how to save a document to a specific version of HTML.

Document doc = new Document(MyDir + "Rendering.docx");

                                                                      HtmlSaveOptions options = new HtmlSaveOptions(SaveFormat.Html)
                                                                      {
                                                                          HtmlVersion = htmlVersion,
                                                                          PrettyFormat = true
                                                                      };

                                                                      doc.Save(ArtifactsDir + "HtmlSaveOptions.HtmlVersions.html", options);

                                                                      // Our HTML documents will have minor differences to be compatible with different HTML versions.
                                                                      string outDocContents = File.ReadAllText(ArtifactsDir + "HtmlSaveOptions.HtmlVersions.html");

                                                                      switch (htmlVersion)
                                                                      {
                                                                          case HtmlVersion.Html5:
                                                                              Assert.That(outDocContents.Contains("<a id=\"_Toc76372689\"></a>"), Is.True);
                                                                              Assert.That(outDocContents.Contains("<a id=\"_Toc76372689\"></a>"), Is.True);
                                                                              Assert.That(outDocContents.Contains("<table style=\"padding:0pt; -aw-border:0.5pt single #000000; -aw-border-insideh:0.5pt single #000000; -aw-border-insidev:0.5pt single #000000; border-collapse:collapse\">"), Is.True);
                                                                              break;
                                                                          case HtmlVersion.Xhtml:
                                                                              Assert.That(outDocContents.Contains("<a name=\"_Toc76372689\"></a>"), Is.True);
                                                                              Assert.That(outDocContents.Contains("<ul type=\"disc\" style=\"margin:0pt; padding-left:0pt\">"), Is.True);
                                                                              Assert.That(outDocContents.Contains("<table cellspacing=\"0\" cellpadding=\"0\" style=\"-aw-border:0.5pt single #000000; -aw-border-insideh:0.5pt single #000000; -aw-border-insidev:0.5pt single #000000; border-collapse:collapse\""), Is.True);
                                                                              break;
                                                                      }
 English