com.aspose.words

Class ExportListLabels

  • java.lang.Object
    • com.aspose.words.ExportListLabels
public class ExportListLabels 
extends java.lang.Object

Utility class containing constants. Specifies how list labels are exported to HTML, MHTML and EPUB.

Example:

Shows how to configure list exporting to HTML.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

List list = doc.getLists().add(ListTemplate.NUMBER_DEFAULT);
builder.getListFormat().setList(list);

builder.writeln("Default numbered list item 1.");
builder.writeln("Default numbered list item 2.");
builder.getListFormat().listIndent();
builder.writeln("Default numbered list item 3.");
builder.getListFormat().removeNumbers();

list = doc.getLists().add(ListTemplate.OUTLINE_HEADINGS_LEGAL);
builder.getListFormat().setList(list);

builder.writeln("Outline legal heading list item 1.");
builder.writeln("Outline legal heading list item 2.");
builder.getListFormat().listIndent();
builder.writeln("Outline legal heading list item 3.");
builder.getListFormat().listIndent();
builder.writeln("Outline legal heading list item 4.");
builder.getListFormat().listIndent();
builder.writeln("Outline legal heading list item 5.");
builder.getListFormat().removeNumbers();

// When saving the document to HTML, we can pass a SaveOptions object
// to decide which HTML elements the document will use to represent lists.
// Setting the "ExportListLabels" property to "ExportListLabels.AsInlineText"
// will create lists by formatting spans.
// Setting the "ExportListLabels" property to "ExportListLabels.Auto" will use the <p> tag
// to build lists in cases when using the <ol> and <li> tags may cause loss of formatting.
// Setting the "ExportListLabels" property to "ExportListLabels.ByHtmlTags"
// will use <ol> and <li> tags to build all lists.
HtmlSaveOptions options = new HtmlSaveOptions();
{
    options.setExportListLabels(exportListLabels);
}

doc.save(getArtifactsDir() + "HtmlSaveOptions.List.html", options);
String outDocContents = FileUtils.readFileToString(new File(getArtifactsDir() + "HtmlSaveOptions.List.html"), StandardCharsets.UTF_8);

switch (exportListLabels) {
    case ExportListLabels.AS_INLINE_TEXT:
        Assert.assertTrue(outDocContents.contains(
                "<p style=\"margin-top:0pt; margin-left:72pt; margin-bottom:0pt; text-indent:-18pt; -aw-import:list-item; -aw-list-level-number:1; -aw-list-number-format:'%1.'; -aw-list-number-styles:'lowerLetter'; -aw-list-number-values:'1'; -aw-list-padding-sml:9.67pt\">" +
                        "<span style=\"-aw-import:ignore\">" +
                        "<span>a.</span>" +
                        "<span style=\"font:7pt 'Times New Roman'; -aw-import:spaces\">&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0; </span>" +
                        "</span>" +
                        "<span>Default numbered list item 3.</span>" +
                        "</p>"));

        Assert.assertTrue(outDocContents.contains(
                "<p style=\"margin-top:0pt; margin-left:43.2pt; margin-bottom:0pt; text-indent:-43.2pt; -aw-import:list-item; -aw-list-level-number:3; -aw-list-number-format:'%0.%1.%2.%3'; -aw-list-number-styles:'decimal decimal decimal decimal'; -aw-list-number-values:'2 1 1 1'; -aw-list-padding-sml:10.2pt\">" +
                        "<span style=\"-aw-import:ignore\">" +
                        "<span>2.1.1.1</span>" +
                        "<span style=\"font:7pt 'Times New Roman'; -aw-import:spaces\">&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0; </span>" +
                        "</span>" +
                        "<span>Outline legal heading list item 5.</span>" +
                        "</p>"));
        break;
    case ExportListLabels.AUTO:
        Assert.assertTrue(outDocContents.contains(
                "<ol type=\"a\" style=\"margin-right:0pt; margin-left:0pt; padding-left:0pt\">" +
                        "<li style=\"margin-left:31.33pt; padding-left:4.67pt\">" +
                        "<span>Default numbered list item 3.</span>" +
                        "</li>" +
                        "</ol>"));

        Assert.assertTrue(outDocContents.contains(
                "<p style=\"margin-top:0pt; margin-left:43.2pt; margin-bottom:0pt; text-indent:-43.2pt; -aw-import:list-item; -aw-list-level-number:3; " +
                        "-aw-list-number-format:'%0.%1.%2.%3'; -aw-list-number-styles:'decimal decimal decimal decimal'; " +
                        "-aw-list-number-values:'2 1 1 1'; -aw-list-padding-sml:10.2pt\">" +
                        "<span style=\"-aw-import:ignore\">" +
                        "<span>2.1.1.1</span>" +
                        "<span style=\"font:7pt 'Times New Roman'; -aw-import:spaces\">&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0; </span>" +
                        "</span>" +
                        "<span>Outline legal heading list item 5.</span>" +
                        "</p>"));
        break;
    case ExportListLabels.BY_HTML_TAGS:
        Assert.assertTrue(outDocContents.contains(
                "<ol type=\"a\" style=\"margin-right:0pt; margin-left:0pt; padding-left:0pt\">" +
                        "<li style=\"margin-left:31.33pt; padding-left:4.67pt\">" +
                        "<span>Default numbered list item 3.</span>" +
                        "</li>" +
                        "</ol>"));

        Assert.assertTrue(outDocContents.contains(
                "<ol type=\"1\" class=\"awlist3\" style=\"margin-right:0pt; margin-left:0pt; padding-left:0pt\">" +
                        "<li style=\"margin-left:7.2pt; text-indent:-43.2pt; -aw-list-padding-sml:10.2pt\">" +
                        "<span style=\"font:7pt 'Times New Roman'; -aw-import:ignore\">&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0; </span>" +
                        "<span>Outline legal heading list item 5.</span>" +
                        "</li>" +
                        "</ol>"));
        break;
}
See Also:
HtmlSaveOptions.ExportListLabels

Field Summary
static final intAUTO = 0
Outputs list labels in auto mode. Uses HTML native elements when possible.
static final intAS_INLINE_TEXT = 1
Outputs all list labels as inline text.
static final intBY_HTML_TAGS = 2
Outputs all list labels as HTML native elements.
 

    • Field Detail

      • AUTO = 0

        public static final int AUTO
        Outputs list labels in auto mode. Uses HTML native elements when possible. HTML <ul> and <ol> tags are used for list label representation if it doesn't cause formatting loss, otherwise the HTML <p> tag is used.
      • AS_INLINE_TEXT = 1

        public static final int AS_INLINE_TEXT
        Outputs all list labels as inline text. HTML <p> tag is used for any list label representation.
      • BY_HTML_TAGS = 2

        public static final int BY_HTML_TAGS
        Outputs all list labels as HTML native elements. HTML <ul> and <ol> tags are used for list label representation. Some formatting loss is possible.