Aspose::Words::Saving::HtmlVersion enum
Contents
[
Hide
]HtmlVersion enum
Indicates the version of HTML is used when saving the document to Html and Mhtml formats.
enum class HtmlVersion
Values
Name | Value | Description |
---|---|---|
Xhtml | 0 | Saves the document in compliance with the XHTML 1.0 Transitional standard. |
Html5 | 1 | Saves the document in compliance with the HTML 5 standard. |
Examples
Shows how to save a document to a specific version of HTML.
auto doc = System::MakeObject<Aspose::Words::Document>(get_MyDir() + u"Rendering.docx");
auto options = System::MakeObject<Aspose::Words::Saving::HtmlSaveOptions>(Aspose::Words::SaveFormat::Html);
options->set_HtmlVersion(htmlVersion);
options->set_PrettyFormat(true);
doc->Save(get_ArtifactsDir() + u"HtmlSaveOptions.HtmlVersions.html", options);
// Our HTML documents will have minor differences to be compatible with different HTML versions.
System::String outDocContents = System::IO::File::ReadAllText(get_ArtifactsDir() + u"HtmlSaveOptions.HtmlVersions.html");
switch (htmlVersion)
{
case Aspose::Words::Saving::HtmlVersion::Html5:
ASSERT_TRUE(outDocContents.Contains(u"<a id=\"_Toc76372689\"></a>"));
ASSERT_TRUE(outDocContents.Contains(u"<a id=\"_Toc76372689\"></a>"));
ASSERT_TRUE(outDocContents.Contains(u"<table style=\"padding:0pt; -aw-border-insideh:0.5pt single #000000; -aw-border-insidev:0.5pt single #000000; border-collapse:collapse\">"));
break;
case Aspose::Words::Saving::HtmlVersion::Xhtml:
ASSERT_TRUE(outDocContents.Contains(u"<a name=\"_Toc76372689\"></a>"));
ASSERT_TRUE(outDocContents.Contains(u"<ul type=\"disc\" style=\"margin:0pt; padding-left:0pt\">"));
ASSERT_TRUE(outDocContents.Contains(u"<table cellspacing=\"0\" cellpadding=\"0\" style=\"-aw-border-insideh:0.5pt single #000000; -aw-border-insidev:0.5pt single #000000; border-collapse:collapse\""));
break;
}
Shows how to display a DOCTYPE heading when converting documents to the Xhtml 1.0 transitional standard.
auto doc = System::MakeObject<Aspose::Words::Document>();
auto builder = System::MakeObject<Aspose::Words::DocumentBuilder>(doc);
builder->Writeln(u"Hello world!");
auto options = System::MakeObject<Aspose::Words::Saving::HtmlSaveOptions>(Aspose::Words::SaveFormat::Html);
options->set_HtmlVersion(Aspose::Words::Saving::HtmlVersion::Xhtml);
options->set_ExportXhtmlTransitional(showDoctypeDeclaration);
options->set_PrettyFormat(true);
doc->Save(get_ArtifactsDir() + u"HtmlSaveOptions.ExportXhtmlTransitional.html", options);
// Our document will only contain a DOCTYPE declaration heading if we have set the "ExportXhtmlTransitional" flag to "true".
System::String outDocContents = System::IO::File::ReadAllText(get_ArtifactsDir() + u"HtmlSaveOptions.ExportXhtmlTransitional.html");
if (showDoctypeDeclaration)
{
ASSERT_TRUE(outDocContents.Contains(System::String(u"<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\r\n") + u"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\r\n" + u"<html xmlns=\"http://www.w3.org/1999/xhtml\">"));
}
else
{
ASSERT_TRUE(outDocContents.Contains(u"<html>"));
}
See Also
- Namespace Aspose::Words::Saving
- Library Aspose.Words for C++