Extract section with Numbering

Hi,

I want to extract section with Numbering.

When I extract section and convert in into html. Then it always start from Numbering 1.
Numbering Section.zip (21.6 KB)

I have attached my project to extract document, please check it.
com.aspose.words.zip (5.2 MB)

@ngshinde999

Thanks for your inquiry. You are facing the expected behavior of Aspose.Words. If you extract the contents using MS Word and copy them into new document, you will get the same output.

In this case, we suggest you following solution.

  1. Get the list label before extracting the content e.g 1, 2 etc.
  2. After calling generateDocument method, set the starting number for list level using ListLevel.StartAt property for the list in the extracted document.

Hi,
Thanks for you reply,

I am using Aspose Word - Java (18.9 version)

I was referring following url
https://github.com/aspose-words/Aspose.Words-for-Java

I tried using above solution but I could not get exact output.

Can you please give me some example code.

Thanks…

@ngshinde999

Thanks for your inquiry. Please use the following modified code example to get the desired output. Hope this helps you.

Document doc = new Document(MyDir + "AIR4548A_conv_2017.10.25.docx");
doc.updateListLabels();
int i = 1;
DocumentBuilder builder = new DocumentBuilder(doc);
NodeCollection nodes = doc.getChildNodes(NodeType.PARAGRAPH, true);
for (Paragraph para : (Iterable<Paragraph>) nodes) {
    if (para.getParagraphFormat().isHeading() && para.getParagraphFormat().getStyleName().equals("Heading 1")) {
        if (para.getParagraphFormat().isListItem())
        {
            int label = para.getListLabel().getLabelValue();
        }
        Paragraph paragraph = new Paragraph(doc);
        para.getParentNode().insertBefore(paragraph, para);

        builder.moveTo(paragraph);
        builder.startBookmark("bm_extractcontents" + i);
        builder.endBookmark("bm_extractcontents" + i);
        i++;
    }
}

builder.moveToDocumentEnd();
builder.startBookmark("bm_extractcontents" + i);
builder.endBookmark("bm_extractcontents" + i);

HtmlSaveOptions options = new HtmlSaveOptions();
options.setExportListLabels(ExportListLabels.AS_INLINE_TEXT);
doc.save(MyDir + "out//18.11.html", options);
doc = new Document(MyDir + "out//18.11.html");

for (int bm = 1; bm < i; bm++) {

    BookmarkStart bookmarkStart = doc.getRange().getBookmarks().get("bm_extractcontents" + bm)
            .getBookmarkStart();

    BookmarkStart bookmarkEnd = doc.getRange().getBookmarks().get("bm_extractcontents" + (bm + 1))
            .getBookmarkStart();

    ArrayList extractedNodes = ExtractContents.extractContent(bookmarkStart, bookmarkEnd, false);

    Document dstDoc = ExtractContents.generateDocument(doc, extractedNodes);
    dstDoc.save(MyDir + "out//Out" + bm + ".html");
}