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

Free Support Forum - aspose.com

Rendering image of the sheet includes extra white space

I am using Aspose Cells 8.1.0 to create image of the sheet.


I want the image of the sheet to only include the cells that have data with the option of OnePagePerSheet turned on.

However, the image rendered contains lot of white space when I set OnePagePerSheet as true. Image is rendered properly (means without any white space) when I set OnePagePerSheet to false. But I cannot set this to false as there are other cases where data does not fit to one page and I want all the data of the sheet to fit in the single page.

I tried following to achieve this:
- Setting the print area of the populated cells
- Setting ImageFitToPage in ImageOrPrintOptions to true
However no success with both of these.

Is there any option to achieve the desired usecase?

For your reference, I have attached the source excel file and both outputs with OnePagePerSheet as true and false. To analyze the difference between the two images, you may need to open images in MS Paint.

Following is the code snippet being used:
Workbook workbook = new Workbook(“C:/temp/source.xlsx”);
com.aspose.cells.Worksheet sheet = workbook.getWorksheets().get(0);

sheet.getPageSetup().setPrintArea(“A1:D3”);

ImageOrPrintOptions imageOrPrintOptions = new ImageOrPrintOptions();
imageOrPrintOptions.setImageFormat(ImageFormat.getPng());
imageOrPrintOptions.setHorizontalResolution(300);
imageOrPrintOptions.setVerticalResolution(300);
imageOrPrintOptions.setOnePagePerSheet(false);
imageOrPrintOptions.setOnlyArea(true);

SheetRender sr = new SheetRender(sheet, imageOrPrintOptions);
sr.toImage(0, “c:/temp/out2.png”);



Hi Neeraj,

Thanks for your posting and using Aspose.Cells.

Please set all the margins to 0 and it will fix your issue. Please see the following code for your reference. I have also attached the output image generated by it.

Java


Workbook workbook = new Workbook(“source.xlsx”);

com.aspose.cells.Worksheet sheet = workbook.getWorksheets().get(0);


sheet.getPageSetup().setPrintArea(“A1:D3”);


sheet.getPageSetup().setTopMargin(0);

sheet.getPageSetup().setBottomMargin(0);

sheet.getPageSetup().setRightMargin(0);

sheet.getPageSetup().setLeftMargin(0);


ImageOrPrintOptions imageOrPrintOptions = new ImageOrPrintOptions();

imageOrPrintOptions.setImageFormat(ImageFormat.getPng());

imageOrPrintOptions.setHorizontalResolution(300);

imageOrPrintOptions.setVerticalResolution(300);

imageOrPrintOptions.setOnePagePerSheet(true);


SheetRender sr = new SheetRender(sheet, imageOrPrintOptions);

sr.toImage(0, “out3.png”);

Hi,


Thanks that worked fine.

Thanks,
Neeraj

Hi,


Good to know that it figures out your issue. Feel free to write back if you have further comments or questions, we will be happy to assist you soon.

Thank you.