How to control and set some settings in Microsoft Word by using essential file formats for Java?

Hi Syncfusion Team:


I have a few questions about Word document processing:


Question 1: how to control and set the first line of a paragraph to indent two characters in Microsoft Word?


Question 2: how to control and set the Chinese font and Western Font in a paragraph of Microsoft Word? To be specific, a sentence in a paragraph can be written in both Chinese and English, with "黑体" in Chinese and "Times New Roman" in English.


Question 3: how to control Microsoft Word to get the total number of pages occupied by a WSection?


Looking forward to your reply, thank you.


1 Reply

LB Lokesh Baskar Syncfusion Team July 13, 2021 05:44 PM UTC

Hi Bingxueyinlian, 
 
Thank you for contacting Syncfusion support.

 
Queries 
Details 
How to control and set the first line of a paragraph to indent two characters in Microsoft Word? 
Please refer the below UG documentation to set indent for the paragraphs.
https://help.syncfusion.com/java-file-formats/word-library/working-with-paragraph#applying-paragraph-formatting
 
How to control and set the Chinese font and Western Font in a paragraph of Microsoft Word? 
Please refer the below code snippet to set Chinese font and Western Font for a paragraph text range. 


 
//Create a new Word document. 
WordDocument document = new WordDocument(); 
//Add a new section to the document. 
IWSection section = document.addSection(); 
//Add a new paragraph to the section. 
IWParagraph firstParagraph = section.addParagraph(); 
//Add a new text to the paragraph. 
IWTextRange firstText = firstParagraph.appendText("们所有的设备和仪器彷佛都是有生命的"); 
//Apply formatting for the first text range. 
firstText.getCharacterFormat().setFontName("Noto Sans SC"); 
IWTextRange secondText = firstParagraph.appendText("This the second text range"); 
//Apply formatting for the second text range. 
secondText.getCharacterFormat().setFontName("Times New Roman"); 
//Save the Word document. 
document.save("Sample.docx", FormatType.Docx); 
//Close the document. 
document.close(); 
 


 
 
How to control Microsoft Word to get the total number of pages occupied by a WSection? 
The Word document is a flow document in which contents will not be preserved page by page; instead, the contents will be preserved sequentially section by section. Each section may extend to various pages based on its contents like table, text, images etc. 
 
Word viewer/editor renders the contents of the Word document page by page dynamically when opened for viewing or editing and this page wise rendered information will not be preserved in the document level as per the Word file format specification. 
 
Whereas Essential DocIO(JAVA) is a non-UI component that provides a full-fledged document object model to manipulate the Word document contents. Hence currently it is not feasible to get the total number of pages occupied by a WSection in Word document using DocIO(JAVA). 


 
Please let us know if you have any other questions.

 
Regards 
Lokesh B 


Loader.
Up arrow icon