No difference seen between landscape and potrait print aspose

43 views Asked by At

Below is the Java code :

DocumentBuilder w_Bldr = new DocumentBuilder();

The below code is in for loop. Even if w_Bldr.getPageSetup().setOrientation(Orientation.LANDSCAPE); is specified outside loop the print is still the same for both the modes.

w_Bldr.getPageSetup().setOrientation(Orientation.LANDSCAPE); 
// if landscape 
w_Bldr.getPageSetup().setOrientation(Orientation.PORTRAIT); 
// if portrait 
w_Bldr.getParagraphFormat().setKeepWithNext(true); 
w_Bldr.getParagraphFormat().setKeepTogether(true); 
w_Bldr.getRowFormat().setAllowBreakAcrossPages(false); 
w_Bldr.getRowFormat().setAllowAutoFit(false); 
w_Bldr.writeln();

Jars used : Aspose.Words.jdk15.jar aspose-cells-2.5.1.jar

How can this be fixed so that the difference should be noticeable?

Tried setting the pageWidth.

w_Bldr.getPageSetup().setPageWidth(200);

But no difference.

1

There are 1 answers

2
Alexey Noskov On

Page orientation is defined per section in MS Word documents. So to change page orientation section break must be inserted. For example see the following code that produces document with two section, one with portrait page orientation and another with landscape orientation:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
        
builder.getPageSetup().setOrientation(Orientation.PORTRAIT);
builder.writeln("This is PORTRAIT");
        
// Insert section break and change page orientation.
builder.insertBreak(BreakType.SECTION_BREAK_NEW_PAGE);
builder.getPageSetup().setOrientation(Orientation.LANDSCAPE);
builder.writeln("This is PORTRAIT");
    
doc.save("C:\\Temp\\out.docx");