Hi Team,
For my project ,I am taking the word document(html) and converting it into pdf.Steps that we are following are :
-
Taking default Word Empty document from project workspace.
-
Creating builder of this word file using aspose code :
final com.aspose.words.Document asposeDoc = new com.aspose.words.Document(defaultWordFile);
final DocumentBuilder builder = new DocumentBuilder(asposeDoc);
-
Inserting htmlInput to this asposeDoc using below code.
builder.insertHtml(Inputhtml);
-
Saving builder.getdocument to designated path using below code :
builder.getDocument().save(designatedPath);
-
Applying indentation formatting to Word document in designated path to correct bullet spacing and text spacing and finally saving the Word file again there .The code (correctindentationusingaspose) is given below.
-
The word file is finally converted to PDF using java Method.
The issue that I am facing here is as follows:
-
Inputhtml file has to be in the format as attached.I want it should able to work with Expected htmlInput.
-
If I am giving the ExpectedhtmlInput to asposeDoc.The correct indentation code is not working on that.
Below is correct indentation code I am using:
private Input Stream correctindentationusingaspose(final String designatedPath) throws Exception {
Document doc = new Document(designatedPath);
DocumentBuilder builder = new DocumentBuilder(designatedPath);
int count = 0;
int i = 0;
int j = 8;
for (Paragraph para : (Iterable)doc.getChildNodes(NodeType.PARAGRAPH , true))
{
if(para.isListItem())
{
count++;
final int one = 1;
final String ONE = Integer.toString(one);
final String COUNT = Integer.toString(count);
if (COUNT.equalsIgnoreCase(ONE)){
com.aspose.words.List list1 = para.getListFormat().getList();
ListLevel level1 = list1.getListLevels().get(0);
level1.setNumberPosition(i);
level1.setTabPosition(j); level1.setTrailingCharacter(ListTrailingCharacter.TAB);
i=i+10;
j=j+10;
}
else{
com.aspose.words.List list0 = para.getListFormat().getList();
ListLevel level0 = list0.getListLevels().get(0);
level0.setNumberPosition(i);
level0.setTabPosition(j);
level0.setTrailingCharacter(ListTrailingCharacter.TAB);
i=i+10;
j=j+10;
}
}
}
doc.save(designatedPath);
InputStream stream = new FileInputStream(designatedPath);
return stream;
}
Kindly assist here why this is happening here.What step I can modiy or add so that ExpectedHtmlInput added to asposeDoc can also be edited.
Attached are HtmlInput files,InputWordfile created that is asposeDoc and Output wordFiles for both cases.Please let me know if u nedd more info.
Appreciate for soon reply.
Regards
Thanks
Sonam Arora