Hi,
Let me try to give you a brief background of our requirement. Our use case is to create document and then split the document in single page document and then merge the splitted documents and convert them to html and send it to the user. This is done to provide pagination .
Now the issue is that when we merge the documents , the indentation/list numbering is incorrect . Numbering in single page documents is correct , but when we merge , the numbering is incorrect. Attaching the main document , single page documents and screen-shot of the incorrect numbering.
Code to split the document :
LayoutCollector layoutCollector = new LayoutCollector(document);
DocumentPageSplitter splitter = new DocumentPageSplitter(layoutCollector);
Integer priviousListLevel = null;
for (int page = 1; page <= document.getPageCount(); page++) {
Document newDoc = splitter.getDocumentOfPage(page);
newDoc.updateListLabels();
if (priviousListLevel != null) {
for (Paragraph para : (Iterable<Paragraph>) newDoc.getChildNodes(NodeType.PARAGRAPH, true)) {
if (para.isListItem()) {
com.aspose.words.List list = para.getListFormat().getList();
list.getListLevels().get(0).setStartAt(priviousListLevel + 1);
break;
}
}
}
priviousListLevel = null;
int labelValue = 0;
Node[] nodes = newDoc.getChildNodes(NodeType.PARAGRAPH, true)
.toArray();
for (int i = nodes.length - 1; i >= 0; i--) {
Paragraph paragraph = (Paragraph) nodes[i];
if (paragraph.getListFormat().isListItem() && paragraph.getListFormat().getListLevelNumber() == 0) {
ListLabel label = paragraph.getListLabel();
labelValue = label.getLabelValue();
priviousListLevel = labelValue;
break;
}
}
newDoc.getRange().replace(AdminTemplateConstants.TAG_IDENTIFIER_PATTERN, new ReplaceEvaluator(false, templateStyle.getGeneralFont()), false);
newDoc.save(folder + "/" + page + AdminTemplateConstants.DOC_EXTENSION);
}
…
Code for merging document :
for (Document sourceDocument : documentsToMerge) {
com.aspose.words.List list = null;
for (Paragraph para : (Iterable<Paragraph>) startdocument.getChildNodes(
NodeType.PARAGRAPH, true)) {
if (para.isListItem() && para.getListFormat().getListLevelNumber() == 0) {
list = para.getListFormat().getList();
break;
}
}
if (list != null) {
com.aspose.words.List newList = sourceDocument.getLists().addCopy(list);
for (Paragraph para : (Iterable<Paragraph>) sourceDocument.getChildNodes(
NodeType.PARAGRAPH, true)) {
if (para.isListItem() && para.getListFormat().getListLevelNumber() == 0) {
para.getListFormat().setList(newList);
}
}
}
startdocument.appendDocument(sourceDocument, ImportFormatMode.USE_DESTINATION_STYLES);
}
…
Code for converting doc to html
HtmlFixedSaveOptions saveOptions = new HtmlFixedSaveOptions();
saveOptions.setExportEmbeddedCss(true);
saveOptions.setExportEmbeddedFonts(true);
saveOptions.setExportEmbeddedImages(true);
saveOptions.setExportEmbeddedSvg(true);
saveOptions.setExportFormFields(true);
saveOptions.setEncoding(StandardCharsets.ISO_8859_1);
return saveOptions;
We are really struck at that. Please help
Documents.zip (191.9 KB)