In my project I am extracting content between some characters from uploaded word document using Aspose and save it in the data base. if customer click document download option I am fetching a customer template and replace a special word with all the extracted content. So i want the downloaded document should be and uploaded document should be save.
If uploaded or template document’s Normal style contains paragraph numbering. If uploaded document input.docx (21.3 KB) contains paragraph number with negative indentation. Also removed numbering from certain paragraph. But in downloaded document output.docx (14.2 KB) not contains negative indentation and paragraph number removed paragraph also contains paragraph.
my expected document same as inputinput.docx (21.3 KB)
attaching sample code paragraph numbering.zip (152.1 KB)
@Gptrnt In your code you store part of document content as HTML. It is not always possible to retain all MS Word document formatting in HTML. I have modified your code to use FlatOpc (MS Word 2007 XML) format instead of HTML and the result produced looks like what you need. Here are code modifications I have made:
I have replaced htmlSaveOption method with the following:
I have go through your code and your output. In that negative indentation is issue is fixing, but in all paragraph having paragraph numbering. As you can see in my input document after 8th and 10th paragraph I am removed the numbering. But in output file that paragraph also contains the numbering. Please give a solution considering with this scenario also.
@Gptrnt There are two reasons of the problem with numbering.
In your code you extract only the first item.
here is the modified code:
private static List<HashMap<String,String>> SaveInItem(BookmarkCollection bookmarkCollection, Document document, SaveOptions saveOptions) {
List<HashMap<String,String>> item = new ArrayList<>();
for (int i =1;i<=5; i ++){
HashMap<String,String> details = new HashMap<>();
details.put("Title",getTitle(bookmarkCollection,i));
details.put("Note",getHtmlContentFromBookMark("m", bookmarkCollection, document, saveOptions, i));
details.put("Description",getHtmlContentFromBookMark("f", bookmarkCollection, document, saveOptions, i));
item.add(details);
}
return item;
}
You are using old 21.1 version of Aspose.Words for Java. After updating the version to the latest 22.1, the problem does not occur: output.docx (16.5 KB) output.pdf (70.9 KB)
FlatOpc format is not supported for exporting fragments, but in your case you extract content into a separate document, so you can simply save the fragment document to stream and then convert the stream to string, like demonstrated in the code above.
I have tried the solution. While testing with the solution I have encounter some other issue with some html Can you help me with any other solution for the issue .
@Gptrnt Could you please elaborate what problems you encountered with the suggested approach? If possible please attach sample input, output and expected documents, here for testing. We will check the issues and provide you more information.