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

Free Support Forum - aspose.com

The orientation of paper is not changed in landscape mode

To change the orientation of paper, i have used this function:

pageSetup.setOrientation(PageOrientationType.LANDSCAPE);

After that, the orientation of data is changed, but the orientation of the paper is not. Please help me resolve this problem

Please see my attach file to get more detail.

Hi,


Well, Aspose.Cells works the same way as per MS Excel (it renders the same output as per MS Excel’s print preview for the worksheet(s)). You may convert your Excel spreadsheet (after setting the Orientation (in PageSetup dialog box) to Landscape) manually and then convert to PDF (via Excel’s built-in renderer), you will see the same results as per your attached output PDF file. If you still think Aspose.Cells does not render PDF file as per MS Excel, please provide your template file with your desired settings, we will check it soon.

Thank you.

hi


I attached two file pdf which were printed by aspose-cell and Excel in landscape mode. There is a different in paper orientation. I want the result of printed data by Aspose-cell must same as with Excel.

Please help me check its. It is urgent. Thanks you


Hi,


Thanks for the template Excel file and PDF files.

Please try our latest version/ fix: Aspose.Cells for Java v8.8.0.2
I have tested your scenario/ case using the following sample code with v8.8.0.2, it works fine and as expected. Please find attached the output PDF file for your reference.
e.g
Sample code:

System.out.println(CellsHelper.getVersion());
Workbook src = new Workbook(“a.xlsx”);
PageSetup pageSetup = src.getWorksheets().get(0).getPageSetup();
pageSetup.setOrientation(PageOrientationType.LANDSCAPE);
src.save(“out1a1.pdf”);

Let us know if you still have any issue.

Thank you.

i have already used lastest version: 8.8.0


i have tried your code. It is ok. But my bug still exist, because i don’t use the function: "src.save(“out1a1.pdf”);"

In my application, i use this function: “sr.toPrinter(printerName);” with printerName is a pdf printer or xps printer, and the output is wrong (the orientation of the paper is portrait while the orientation of the data is landscape). But when i use excel with same printer and landscape mode, the output file is correct.

Please test it again:

ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
//Get the first worksheet
Worksheet sheet = wb.getWorksheets().get(0);
//Create a SheetRender object with respect to your desired sheet
PageSetup pageSetup = sheet.getPageSetup();
// Page orientation
pageSetup.setOrientation(PageOrientationType.LANDSCAPE);
SheetRender sr = new SheetRender(sheet, imgOptions);
//Print the worksheet
wb.save(“out1a1.pdf”);
sr.toPrinter(printerName);

with printerName is “Foxit reader PDF Printer” or “Microsoft XPS Document writer”


Hi Cao,


Thank you for sharing the code snippet to replicate the exact scenario. We have reevaluated the presented scenario while using the latest version of Aspose.Cells for Java 8.8.0.2, and we are able to notice the said problem. Please note, we have used the virtual printer by the name “Adobe PDF” to send the prints from Excel as well as Aspose.Cells for Java API. We have noticed that in case of Aspose.Cells for Java API, the resultant PDF has the paper orientation as portrait but the data orientation is landscape. We have raised these concerns with the product team by logging an investigative ticket under the Id CELLSJAVA-41828. Please spare us little time to properly analyze the scenario and get back with updates in this regard.

Wait the release version seem very long, but our task is very urgent.


How long will the Aspose-cell release new version from now?
Or is there any ways to fix this problem?

Hi Cao,


This is to update you that we have looked further into the details of the matter logged earlier as CELLSJAVA-41828. I am afraid, it is the limitation of Aspose.Cells for Java API (.NET API has no such limitation) that while printing to a virtual printer the result is different from what Excel generates for similar PageSetup configurations. However, if you print to an actual printer, the result will match the Excel exactly. Moreover, if you intend to use SheetRender.toPrinter method render in PDF & XPS formats, we suggest you to use the Workbook.save method to render the whole spreadsheet or a part of it to PDF & XPS formats.

That said, unfortunately, we cannot find a quick fix for this situation however, we will keep the aforementioned ticket open, and try to provide the fix with future releases of Aspose.Cells for Java API.

We are sorry for the inconvenience caused to you.

I have read about function workbook.save()

But i have a question:

How can i save a sheet as PDF by using save() function?
Example: my workbook has 3 sheets. And i only want to save the second sheet to PDF?

Hi Cao,


Please review the article on saving each worksheet to separate PDF. This will give you some idea on how you can use the Aspose.Cells for Java APIs to render a particular worksheet to PDF. Please note, the trick is to hide all unwanted worksheets using the Workhseet.Visible property while keeping the desired worksheet visible and render the workbook to PDF format.

Following snippet make use of the attached spreadsheet to render only the second worksheet to PDF format.

Java

Workbook book = new Workbook(dir + “book1.xlsx”);
for(int i = 0 ; i< book.getWorksheets().getCount() ; i++)
{
Worksheet sheet = book.getWorksheets().get(i);
if (i == 1)
{sheet.setVisible(true);}
else
{sheet.setVisible(false);}
}
book.save(dir + “output.pdf”);