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):
- Orientation flag should be set to 0 (LANDSCAPE) ✓ This works
- 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)
- PDF conversion should honor the landscape orientation
Actual Behavior
When calling pageSetup.setOrientation(PageOrientationType.LANDSCAPE):
- Orientation flag IS set to 0 (LANDSCAPE) ✓
- 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)
- PDF conversion uses the paper dimensions (not the orientation flag)
- 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:
- Open
hidden1.xlsxin Excel - Navigate to Tab2 worksheet
- Verify it is set to landscape orientation in Excel (File → Page Setup → Page → Orientation → Landscape)
- Run the minimal test case above
- Observe that orientation flag is set correctly, but paper dimensions are NOT swapped
- 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:
- The worksheet has landscape orientation in Excel
- Converting to PDF using Aspose.Cells
- The orientation setting is not respected in the final PDF
Workaround Status
No workaround available:
setPaperWidth()andsetPaperHeight()methods do not exist
Setting orientation multiple times does not help
Clearing FitToPages does not help
Setting orientation at different points in the code does not help
Converting only the single worksheet (no multi-sheet interference) does not help
The only potential workaround would be if Aspose provides:
- Methods to manually set paper width/height, OR
- A flag to force PDF orientation to match the orientation setting, OR
- A fix to automatically swap paper dimensions when orientation changes
Expected Fix
When setOrientation(PageOrientationType.LANDSCAPE) is called:
-
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; } -
OR provide setter methods to manually control paper dimensions:
public void setPaperWidth(double width); public void setPaperHeight(double height); -
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:
- ✓ Set orientation after FitToPages settings
- ✓ Clear FitToPages entirely for landscape sheets
- ✓ Set orientation multiple times at different points
- ✓ Set orientation immediately after paper size
- ✓ Force orientation specifically by worksheet name
- ✓ Convert only the single worksheet (isolated test)
- ✓ 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
- Confirm this is a bug in Aspose.Cells 26.1
- Provide a fix that automatically swaps paper dimensions when orientation changes
- OR provide setter methods (
setPaperWidth(),setPaperHeight()) as a workaround - OR provide a flag in
PdfSaveOptionsto force respect for orientation setting - Provide timeline for when this will be fixed
- 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)