setOrientation(LANDSCAPE) Does Not Update Paper Dimensions

Aspose.Cells Bug Report: setOrientation(LANDSCAPE) Does Not Update Paper Dimensions

Summary

When setting PageSetup.setOrientation(PageOrientationType.LANDSCAPE) on a worksheet, the orientation flag is updated but the paper dimensions (width/height) are NOT swapped to match the landscape orientation. This causes PDF conversion to render the page in portrait orientation despite the orientation flag being set to landscape.

Environment

  • Aspose.Cells Version: 26.1 (Java)
  • Java Version: 17
  • Operating System: Windows 10 (local development)/Linux (production)
  • Build Tool: Gradle 8.13

Expected Behavior

When calling pageSetup.setOrientation(PageOrientationType.LANDSCAPE):

  1. Orientation flag should be set to 0 (LANDSCAPE) ✓ This works
  2. Paper dimensions should be swapped to reflect landscape orientation:
    • If paper was 11" wide × 17" tall (portrait)
    • It should become 17" wide × 11" tall (landscape)
  3. PDF conversion should honor the landscape orientation

Actual Behavior

When calling pageSetup.setOrientation(PageOrientationType.LANDSCAPE):

  1. Orientation flag IS set to 0 (LANDSCAPE) ✓
  2. Paper dimensions are NOT swapped - they remain in portrait orientation:
    • Paper stays 11" wide × 17" tall (portrait dimensions)
    • Should be 17" wide × 11" tall (landscape dimensions)
  3. PDF conversion uses the paper dimensions (not the orientation flag)
  4. Result: PDF is rendered in portrait orientation despite orientation flag = LANDSCAPE

Evidence

Inspection Results

After setting setOrientation(LANDSCAPE) on the worksheet:

Orientation: 0                   ← LANDSCAPE (correct)
PaperWidth: 11.0                 ← WRONG: should be 17.0 for landscape
PaperHeight: 17.0                ← WRONG: should be 11.0 for landscape
PaperSize: 4                     ← Paper size type

Expected landscape dimensions: Width=17.0, Height=11.0
Actual dimensions: Width=11.0, Height=17.0 (portrait)

No Setter Methods Available

When attempting to manually correct the dimensions:

pageSetup.setPaperWidth(17.0);   // Method does NOT exist
pageSetup.setPaperHeight(11.0);  // Method does NOT exist

Both setPaperWidth() and setPaperHeight() methods do not exist in the API, making it impossible to manually correct the paper dimensions after setting orientation.

Steps to Reproduce

Minimal Test Case

import com.aspose.cells.PageOrientationType;
import com.aspose.cells.PdfSaveOptions;
import com.aspose.cells.PrintingPageType;
import com.aspose.cells.Workbook;
import com.aspose.cells.Worksheet;
import java.nio.file.Path;

public class AsposeOrientationBugTest {

    public void demonstrateBug() throws Exception {
        // Load Excel file with Tab2 worksheet
        Workbook workbook = new Workbook("hidden1.xlsx");

        // Get Tab2 worksheet
        Worksheet tab2 = workbook.getWorksheets().get("Tab2");

        // Print BEFORE setting landscape
        System.out.println("BEFORE setOrientation(LANDSCAPE):");
        System.out.println("  Orientation: " + tab2.getPageSetup().getOrientation());
        System.out.println("  PaperWidth: " + tab2.getPageSetup().getPaperWidth());
        System.out.println("  PaperHeight: " + tab2.getPageSetup().getPaperHeight());

        // Clear FitToPages (to eliminate any interference)
        tab2.getPageSetup().setFitToPagesWide(0);
        tab2.getPageSetup().setFitToPagesTall(0);

        // Set orientation to LANDSCAPE
        tab2.getPageSetup().setOrientation(PageOrientationType.LANDSCAPE);

        // Print AFTER setting landscape
        System.out.println("\nAFTER setOrientation(LANDSCAPE):");
        System.out.println("  Orientation: " + tab2.getPageSetup().getOrientation());
        System.out.println("  PaperWidth: " + tab2.getPageSetup().getPaperWidth());
        System.out.println("  PaperHeight: " + tab2.getPageSetup().getPaperHeight());

        // Convert to PDF
        PdfSaveOptions options = new PdfSaveOptions();
        options.setAllColumnsInOnePagePerSheet(false);
        options.setOnePagePerSheet(false);
        options.setPrintingPageType(PrintingPageType.IGNORE_BLANK);

        workbook.save("output.pdf", options);

        // Result: output.pdf shows Tab2 in PORTRAIT orientation
        // despite orientation flag = LANDSCAPE
    }
}

Expected Output

BEFORE setOrientation(LANDSCAPE):
  Orientation: 0 (or 1 if originally portrait)
  PaperWidth: 11.0
  PaperHeight: 17.0

AFTER setOrientation(LANDSCAPE):
  Orientation: 0          ← LANDSCAPE flag (correct)
  PaperWidth: 17.0        ← Should be swapped to 17.0
  PaperHeight: 11.0       ← Should be swapped to 11.0

Actual Output

BEFORE setOrientation(LANDSCAPE):
  Orientation: 0
  PaperWidth: 11.0
  PaperHeight: 17.0

AFTER setOrientation(LANDSCAPE):
  Orientation: 0          ← LANDSCAPE flag (correct)
  PaperWidth: 11.0        ← BUG: NOT swapped (still portrait)
  PaperHeight: 17.0       ← BUG: NOT swapped (still portrait)

Test File

The test file hidden1.xlsx has three worksheets:

  • MC Jira: First worksheet, landscape orientation
  • Tab2: Second worksheet, landscape orientation - THIS IS THE PROBLEMATIC SHEET
  • Tab3: Third worksheet, landscape orientation with manual page breaks

Tab2 specifications:

  • Original orientation in Excel: Landscape (PageOrientationType.LANDSCAPE = 0)
  • Original FitToPages: Wide=1, Tall=1
  • Original Zoom: 43%
  • Hidden columns: 6 columns
  • Paper size: 4 (Legal, 8.5" × 14" or 11" × 17" depending on system)

Test File: hidden1.xlsx

No option to attach an .xlsx file, so please advise on how to get this file to your team for reproducing the issue.

To reproduce:

  1. Open hidden1.xlsx in Excel
  2. Navigate to Tab2 worksheet
  3. Verify it is set to landscape orientation in Excel (File → Page Setup → Page → Orientation → Landscape)
  4. Run the minimal test case above
  5. Observe that orientation flag is set correctly, but paper dimensions are NOT swapped
  6. Open the generated PDF and observe Tab2 is in portrait orientation

Impact

Critical Issue for PDF Generation

This bug makes it impossible to generate landscape-oriented PDFs from Excel worksheets when:

  1. The worksheet has landscape orientation in Excel
  2. Converting to PDF using Aspose.Cells
  3. The orientation setting is not respected in the final PDF

Workaround Status

No workaround available:

  • :x: setPaperWidth() and setPaperHeight() methods do not exist
  • :x: Setting orientation multiple times does not help
  • :x: Clearing FitToPages does not help
  • :x: Setting orientation at different points in the code does not help
  • :x: Converting only the single worksheet (no multi-sheet interference) does not help

The only potential workaround would be if Aspose provides:

  1. Methods to manually set paper width/height, OR
  2. A flag to force PDF orientation to match the orientation setting, OR
  3. A fix to automatically swap paper dimensions when orientation changes

Expected Fix

When setOrientation(PageOrientationType.LANDSCAPE) is called:

  1. Automatically swap paper dimensions to match the new orientation:

    // Pseudo-code for expected behavior
    public void setOrientation(int orientation) {
        int currentOrientation = this.orientation;
    
        if (currentOrientation != orientation) {
            // Swap dimensions when orientation changes
            double tempWidth = this.paperWidth;
            this.paperWidth = this.paperHeight;
            this.paperHeight = tempWidth;
        }
    
        this.orientation = orientation;
    }
    
  2. OR provide setter methods to manually control paper dimensions:

    public void setPaperWidth(double width);
    public void setPaperHeight(double height);
    
  3. OR provide a flag to force PDF to use orientation setting:

    pdfSaveOptions.setRespectOrientationFlag(true);
    

Additional Context

Our Investigation Process

We attempted multiple approaches to work around this issue:

  1. ✓ Set orientation after FitToPages settings
  2. ✓ Clear FitToPages entirely for landscape sheets
  3. ✓ Set orientation multiple times at different points
  4. ✓ Set orientation immediately after paper size
  5. ✓ Force orientation specifically by worksheet name
  6. ✓ Convert only the single worksheet (isolated test)
  7. ✓ Verify orientation flag is actually set correctly

All approaches failed - the PDF is always rendered in portrait because the paper dimensions are not swapped to match the orientation setting.

Root Cause Confirmed

The issue is definitively in Aspose.Cells’ PageSetup.setOrientation() method:

  • The orientation flag is updated correctly
  • The paper dimensions are NOT updated to match
  • PDF conversion uses dimensions, not the flag
  • Result: Portrait PDF despite landscape flag

Request for Aspose

  1. Confirm this is a bug in Aspose.Cells 26.1
  2. Provide a fix that automatically swaps paper dimensions when orientation changes
  3. OR provide setter methods (setPaperWidth(), setPaperHeight()) as a workaround
  4. OR provide a flag in PdfSaveOptions to force respect for orientation setting
  5. Provide timeline for when this will be fixed
  6. Provide workaround if fix will take significant time

Priority

HIGH - This bug prevents generating landscape PDFs from Excel worksheets, which is a core use case for Aspose.Cells PDF conversion functionality.


Prepared by: MasterControl Engineering Team
Date: 2026-02-10
Aspose.Cells Version: 26.1 (Java)

@pblad

You’ve confirmed that calling

pageSetup.setOrientation(PageOrientationType.LANDSCAPE);

sets the orientation flag to LANDSCAPE, but the PaperWidth and PaperHeight values remain unchanged, so the generated PDF is still portrait. According to your observation, the API does not provide setPaperWidth or setPaperHeight methods, and the PDF renderer appears to use the paper dimensions rather than the orientation flag [1].

What we need to investigate further

  1. Please attach the hidden1.xlsx file to this forum thread (or share a download link) so we can reproduce the issue on our side.
  2. Try the minimal test on a workbook that contains only the problematic sheet to eliminate any possible interference from other sheets.

Current situation

  • The behavior you described matches what you reported in the forum post [1].
  • At the moment there is no documented way to swap the paper dimensions programmatically, and the orientation flag alone is not honoured by the PDF conversion.

Possible interim approach

  • As a workaround you might select a paper size that is already defined as landscape (e.g., A4 or Legal in landscape) or adjust the FitToPagesWide/Height settings, though you have indicated these did not meet your requirements.

We will examine the file once it is provided and keep you updated here with any findings or a suitable solution.

@pblad,

Thank you for your detailed post, including the issue description, code snippet, and other relevant details.

To thoroughly and accurately evaluate your issue, we request your template Excel file (“hidden1.xlsx”). Could you please compress the file into a zipped archive and attach it here? You can use the “Upload” tool/button in the reply frame to share the zipped file. Once we receive and download it, we will promptly begin investigating the issue and assist you in resolving it soon.

hidden1.zip (25.0 KB)

@pblad,

Thank you for providing the template Excel file.

I was able to replicate the issue using your template Excel file and the sample code. It seems that the setOrientation(LANDSCAPE) function is not working as expected (page scaling might be one culprit) for the underlying worksheet “Tab2” (as you have demonstrated/mentioned), and as a result, it does not update the paper dimensions at runtime or in the output PDF. We will conduct a thorough evaluation of this issue and may log the necessary ticket(s) for resolution following further testing. We will keep you updated on our findings and progress soon.

Workaround Implemented

We’ve successfully implemented a workaround for the orientation/dimension mismatch bug in Aspose.Cells 26.1.

Problem Confirmed

When reading certain Excel files, Aspose.Cells returns paper dimensions that are reversed from the orientation flag:

Example from hidden2.xlsx:

  • Tab2: Orientation flag = 0 (LANDSCAPE), but dimensions = 11.0×17.0 (portrait dimensions)
  • Tab2 (2): Orientation flag = 1 (PORTRAIT), but dimensions = 17.0×11.0 (landscape dimensions)

Since PDF conversion uses paper dimensions (not the orientation flag) to determine page layout, worksheets appear in the opposite orientation from what’s set in Excel.

Workaround Solution

We detect and correct orientation/dimension mismatches using a two-step approach:

  1. Detection Logic

// LANDSCAPE (0) should have width > height, PORTRAIT (1) should have width < height
int orientation = worksheet.getPageSetup().getOrientation();
double paperWidth = worksheet.getPageSetup().getPaperWidth();
double paperHeight = worksheet.getPageSetup().getPaperHeight();

boolean isLandscapeFlag = (orientation == 0);
boolean isDimensionsLandscape = (paperWidth > paperHeight);
boolean isMismatch = (isLandscapeFlag != isDimensionsLandscape);

  1. Correction Strategy

When a mismatch is detected:
if (isMismatch) {
// Set to OPPOSITE orientation to trigger dimension swap
int oppositeOrientation = isLandscapeFlag ? 1 : 0;
worksheet.getPageSetup().setOrientation(oppositeOrientation);

  // Dimensions are now swapped to match Excel's intended layout
  // KEEP the opposite orientation (do NOT set it back)

}

Why This Works

  1. Setting orientation triggers dimension swap: When you call setOrientation(), Aspose.Cells swaps the paper dimensions
  2. Dimensions control PDF layout: PDF conversion uses dimensions (not the orientation flag) for page layout
  3. We keep opposite orientation: If we set it back to original, dimensions swap back too

Example Behavior

Tab2 (LANDSCAPE in Excel with portrait dimensions 11×17):

  • Detect mismatch: LANDSCAPE flag but portrait dimensions
  • Set to PORTRAIT → dimensions swap to 17×11 (landscape)
  • Keep PORTRAIT flag (counterintuitive but necessary)
  • Result: PDF uses 17×11 dimensions = landscape layout matching Excel ✓

Tab2 (2) (PORTRAIT in Excel with landscape dimensions 17×11):

  • Detect mismatch: PORTRAIT flag but landscape dimensions
  • Set to LANDSCAPE → dimensions swap to 11×17 (portrait)
  • Keep LANDSCAPE flag (counterintuitive but necessary)
  • Result: PDF uses 11×17 dimensions = portrait layout matching Excel ✓

Limitations of Workaround

  1. Orientation flag is opposite of reality: We must set PORTRAIT to get landscape PDF and vice versa
  2. Only works for dimension swaps: If setOrientation() doesn’t swap dimensions, the workaround fails
  3. Counterintuitive code: Setting opposite orientation is confusing for developers
  4. Not a true fix: This is a band-aid solution that works around the core bug

What We Still Need from Aspose

A proper fix that ensures:

  1. Correct dimensions on read: When loading Excel files, paper dimensions should match the orientation flag
  2. OR provide setter methods: Give us setPaperWidth() and setPaperHeight() to manually correct dimensions
  3. OR respect orientation flag in PDF conversion: Make PDF rendering use the orientation flag instead of dimensions

Test Files

  • hidden2.xlsx: Demonstrates the dimension reversal bug across 4 worksheets
  • Available if needed for reproduction/testing

Status

:white_check_mark: Workaround is production-ready and all tests passing
:warning: Still need proper fix from Aspose to remove workaround
:clipboard: This confirms the bug exists and is reproducible
hidden2.zip (29.7 KB)

@pblad ,

According to Microsoft Office document, for papersize 4, the width is 17 inch, the height is 11 inch.
For LANDSCAPE layout, we swap paper width and height.

@pblad ,

We will reconsider the following comment in this document. We will open a ticket to investigate it.

A - fLandscape (1 bit): A bit that specifies the orientation of the printed page. This value MUST be ignored if fNoOrient has a value of 1. Otherwise, the orientation is indicated by values and meanings in the following table.

Value Meaning
0 Portrait orientation, in which the longest edge of the page is vertical.
1 Landscape orientation, in which the longest edge of the page is horizontal.

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): CELLSJAVA-46647

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@pblad ,

I tried some printers in Excel, the printview matches our current result. For Landscape for Paper size 4, the horizontal length is 11 inch, the Vertical length is 17 inch.
Screenshot_Landscape.jpg (271.2 KB)

@pblad ,

Workaround:
Option1:
You can use PaperSizeType.PAPER_TABLOID(paper size 3), the width, height in inch is (11, 17).

//set paper size 3
tab2.getPageSetup().setPaperSize(PaperSizeType.PAPER_TABLOID);

Option 2:
Set custom paper width and height as you required:

//set custom paper width and height in inch
tab2.getPageSetup().customPaperSize(11, 17);