public class HtmlVersion
Example: Example:
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.writeln("Hello world!");
HtmlSaveOptions options = new HtmlSaveOptions(SaveFormat.HTML);
{
options.setHtmlVersion(HtmlVersion.XHTML);
options.setExportXhtmlTransitional(showDoctypeDeclaration);
options.setPrettyFormat(true);
}
doc.save(getArtifactsDir() + "HtmlSaveOptions.ExportXhtmlTransitional.html", options);
// Our document will only contain a DOCTYPE declaration heading if we have set the "ExportXhtmlTransitional" flag to "true".
String outDocContents = FileUtils.readFileToString(new File(getArtifactsDir() + "HtmlSaveOptions.ExportXhtmlTransitional.html"), StandardCharsets.UTF_8);
if (showDoctypeDeclaration)
Assert.assertTrue(outDocContents.contains(
"<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\r\n" +
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\r\n" +
"<html xmlns=\"http://www.w3.org/1999/xhtml\">"));
else
Assert.assertTrue(outDocContents.contains("<html>"));
Document doc = new Document(getMyDir() + "Rendering.docx");
HtmlSaveOptions options = new HtmlSaveOptions(SaveFormat.HTML);
{
options.setHtmlVersion(htmlVersion);
options.setPrettyFormat(true);
}
doc.save(getArtifactsDir() + "HtmlSaveOptions.HtmlVersions.html", options);
// Our HTML documents will have minor differences to be compatible with different HTML versions.
String outDocContents = FileUtils.readFileToString(new File(getArtifactsDir() + "HtmlSaveOptions.HtmlVersions.html"), StandardCharsets.UTF_8);
switch (htmlVersion) {
case HtmlVersion.HTML_5:
Assert.assertTrue(outDocContents.contains("<a id=\"_Toc76372689\"></a>"));
Assert.assertTrue(outDocContents.contains("<a id=\"_Toc76372689\"></a>"));
Assert.assertTrue(outDocContents.contains("<table style=\"border-collapse:collapse\">"));
break;
case HtmlVersion.XHTML:
Assert.assertTrue(outDocContents.contains("<a name=\"_Toc76372689\"></a>"));
Assert.assertTrue(outDocContents.contains("<ul type=\"disc\" style=\"margin:0pt; padding-left:0pt\">"));
Assert.assertTrue(outDocContents.contains("<table cellspacing=\"0\" cellpadding=\"0\" style=\"border-collapse:collapse\">"));
break;
}
Field Summary | ||
---|---|---|
static final int | XHTML | |
Saves the document in compliance with the XHTML 1.0 Transitional standard.
|
||
static final int | HTML_5 | |
Saves the document in compliance with the HTML 5 standard.
|
public static final int XHTML
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.
public static final int HTML_5