Reputation: 3596
I am using aspose-words-15.6.0
api for java. I want to change the page orientation to portrait or landscape
based on the page number.
Scenario:
I've a doc
having 3 pages in it, I want page orientation as follow:
EDIT:
I have tried with DocumentBuilder
, there is a way to achieve this but I am missing something, please refer the screenshot I've attached with this question.
Any help would be greatly appreciated.
Upvotes: 1
Views: 2277
Reputation: 1090
There is no concept of Page in MS Word documents. Pages are created by Microsoft Word on the fly and unfortunately there is no straight forward way that you can use to set orientation per Page. However, you can specify orientation settings for a whole Section using Section.PageSetup.Orientation property and a Section may contain more than just one Page.
Alternatively, you may be able create a separate Section for each page in word document using Aspose.Words and then specify page orientation for each Section corresponding to a particular page. Please report this requirement in Aspose.Words forum, we will then develop code for this requirement and provide you more information.
EDIT:
If you want to build document from scratch, please use the following code:
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.writeln("Content on first page");
builder.getPageSetup().setOrientation(Orientation.PORTRAIT);
builder.insertBreak(BreakType.SECTION_BREAK_NEW_PAGE);
builder.writeln("Content on second page");
builder.getPageSetup().setOrientation(Orientation.LANDSCAPE);
builder.insertBreak(BreakType.SECTION_BREAK_NEW_PAGE);
builder.writeln("Content on third page");
builder.getPageSetup().setOrientation(Orientation.PORTRAIT);
doc.save(getMyDir() + "15.10.0.docx");
I work with Aspose as Developer Evangelist.
Upvotes: 3