We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Word 2 Column page layout setting not applying properly like MS Word

We are convert html to docx file using Aspose word in java.

We have to generate docx file which contents instruction first in single page column. then whatever content we add that we want in 2 column of page.

We code it for this but not getting expected out.
Zip file is enclosed here : Aspose PageLayout Issue.zip (84.9 KB)
Which contents :

  1. Expected Docx file
  2. Java code file
  3. Current Out put file as Java code.

Guide us to get expected docx file result .

@nitinchopkar To get the expected output should add a section break between one column and two columns content:

// ..............
builder.insertBreak(BreakType.SECTION_BREAK_CONTINUOUS);
//divide page into two columns
builder.write("Question Paper");
// ..............

I checked its working by adding “builder.insertBreak(BreakType.SECTION_BREAK_CONTINUOUS)”.
But in case removed “builder.write(“Question Paper”);” line then content of 2 column page shifted to next page and document layout also seen to be disturbed.

Updated Code and out put file enclosed here in zip: Aspose PageLayout Issue.zip (629.8 KB)

@nitinchopkar Unfortunately, I cannot see the mentioned problem. in both document you have attached two column section is displayed on the same page with one column first section:

Oh, that was incorrect information given.
Current zip file enclosed here which contains code file, current out put and excepted out put docx file.
Aspose PageLayout Issue.zip (61.4 KB)

@nitinchopkar Could you please also attach the documents, which are inserted by these lines of code:

// ......
builder.insertDocument(new Document(new ByteArrayInputStream(instruction.toString().getBytes(StandardCharsets.UTF_8) )), ImportFormatMode.USE_DESTINATION_STYLES);
// ......
builder.insertDocument(new Document(new ByteArrayInputStream(questionPaper.toString().getBytes(StandardCharsets.UTF_8) )), ImportFormatMode.USE_DESTINATION_STYLES);

It looks like page size from the inserted document is used and since page sizes in sections are different, MS Word shows the section on different pages.

That java file already contents that document page setting code what I enclosed in my earlier post.

And that line of code I taken from aspose document
https://reference.aspose.com/words/net/aspose.words/documentbuilder/insertdocument/

Please give me clarity what exactly you want.

Problem is resolved by setting page size as LETTER.

DocumentBuilder builder = new DocumentBuilder();
				
PageSetup ps = builder.getPageSetup();
ps.setPaperSize(PaperSize.LETTER);
ps.setOrientation(Orientation.PORTRAIT);

Thank you.

@nitinchopkar It is perfect that you managed to fix the issue. Please feel free to ask in case of any issues. We are always glad to help you.