Aspose::Words::Saving::HtmlSaveOptions::get_CssClassNamePrefix method

HtmlSaveOptions::get_CssClassNamePrefix method

Specifies a prefix which is added to all CSS class names. Default value is an empty string and generated CSS class names have no common prefix.

System::String Aspose::Words::Saving::HtmlSaveOptions::get_CssClassNamePrefix() const

Remarks

If this value is not empty, all CSS classes generated by Aspose.Words will start with the specified prefix. This might be useful, for example, if you add custom CSS to generated documents and want to prevent class name conflicts.

If the value is not null or empty, it must be a valid CSS identifier.

Examples

Shows how to save a document to HTML, and add a prefix to all of its CSS class names.

auto doc = MakeObject<Document>(MyDir + u"Paragraphs.docx");

auto saveOptions = MakeObject<HtmlSaveOptions>();
saveOptions->set_CssStyleSheetType(CssStyleSheetType::External);
saveOptions->set_CssClassNamePrefix(u"myprefix-");

doc->Save(ArtifactsDir + u"HtmlSaveOptions.CssClassNamePrefix.html", saveOptions);

String outDocContents = System::IO::File::ReadAllText(ArtifactsDir + u"HtmlSaveOptions.CssClassNamePrefix.html");

ASSERT_TRUE(outDocContents.Contains(u"<p class=\"myprefix-Header\">"));
ASSERT_TRUE(outDocContents.Contains(u"<p class=\"myprefix-Footer\">"));

outDocContents = System::IO::File::ReadAllText(ArtifactsDir + u"HtmlSaveOptions.CssClassNamePrefix.css");

ASSERT_TRUE(outDocContents.Contains(String(u".myprefix-Footer { margin-bottom:0pt; line-height:normal; font-family:Arial; font-size:11pt; -aw-style-name:footer }\r\n") +
                                    u".myprefix-Header { margin-bottom:0pt; line-height:normal; font-family:Arial; font-size:11pt; -aw-style-name:header }\r\n"));

See Also