Free Support Forum - aspose.com

LineSpacing changes during saving WPS document

mark, I have the homologous problem about wps
Document d = new Document(“E:\Riska.docx”);
d.save(“E:\Riskab.docx”);
I just load a wps docx and save as another docx,but when i open ‘Riskab.docx’,I find the linespcing changed

@wuguowei,

Thanks for your inquiry. Have you tried the latest version of Aspose.Words for Java i.e. 19.11 on your end? In case the problem still remains, please ZIP and upload your input Word document and Aspose.Words generated DOCX file showing the undesired behavior here for testing. We will then investigate the issue on our end and provide you more information.

here is my file
Riska.zip (29.3 KB)
the Riska.docx is src docx,the other is the saved

@wuguowei,

It seems that the issue occurs because the default properties of the document are missing. MS Word adds values depending on version. In this case, you need to specify MS Word version explicitly by using LoadOptions. The following code fixes the issue:

LoadOptions opts = new LoadOptions();
opts.setMswVersion(MsWordVersion.WORD_2013);

Document doc = new Document("E:\\Temp\\Riska\\Riska.docx", opts);
doc.save("E:\\Temp\\Riska\\out.docx", SaveFormat.DOCX);

Hope, this helps.

oh,I just used the ParagraphFormat.clearFormatting().
I found the linespacing not changed,but I don not know why?
code like this:

Document d = new Document(“E:\Riska.docx”);
ParagraphFormat pf = d.getStyles().getDefaultParagraphFormat();
pf.clearFormatting();
d.save(“E:\Riskab.docx”);

@wuguowei,

Please see these input/output Word documents (Docs.zip (19.2 KB)) and try running the following code:

LoadOptions opts = new LoadOptions();
opts.setMswVersion(MsWordVersion.WORD_2013);

Document doc = new Document("E:\\Temp\\Riska\\Riska.docx", opts);

ParagraphFormat pf = doc.getStyles().getDefaultParagraphFormat();
pf.clearFormatting();

doc.save("E:\\Temp\\Riska\\out.docx", SaveFormat.DOCX);

You will see in output document that the ‘Space After’ and ‘Space Before’ values of Paragraph become 0. Hope, this helps.