Issue with SheetRender.toImage() while using setPrintArea() method

I’m trying to render the test file using Aspose cells v19.8 for Java.
I’m using worksheet.getPageSetup().setPrintArea() to define the cell range.
In the exported image, please observe the last page (page #43), there seems be an image on top which there is a small text which got rendered. However, this text belongs to the page number 33. So it looks like this piece of text have been duplicated in page #33 and page #43.

This issue doesn’t exist in MS-Excel’s print preview.

FYI: I don’t want to use onepagepersheet.

Can you please try recreating the issue and provide a probable solution?

Below is the sample code I’m using

     Workbook wb = new Workbook("C:/Ash/test.xlsx");
     Worksheet ws = wb.getWorksheets().get(0);
    
     ImageOrPrintOptions options = new ImageOrPrintOptions();
     options.setImageType(ImageType.PNG);
     ws.getPageSetup().setPaperSize(PaperSizeType.PAPER_A_4);
     ws.getPageSetup().setPrintGridlines(true);
     
     CellArea[] pageBreaks = ws.getPrintingPageBreaks(options);
     
     for (int p=0; p<pageBreaks.length; p++)
     {
        CellArea pageArea = pageBreaks[p];
        ws.getPageSetup().setPrintArea(CellsHelper.cellIndexToName(pageArea.StartRow, pageArea.StartColumn)+":"+CellsHelper.cellIndexToName(pageArea.EndRow, pageArea.EndColumn));
        SheetRender sr = new SheetRender(ws, options);
        sr.toImage(0, "C:/Ash/"+p+".png");
     }

AsposeCellsIssue.zip (174.8 KB)

@askgowda,

Thanks for the template file and sample code.

Please change your code segment as following, it will work as expected:
e.g
Sample code:

Workbook wb = new Workbook("f:\\files\\test.xlsx");
	     Worksheet ws = wb.getWorksheets().get(0);
	    
	     ImageOrPrintOptions options = new ImageOrPrintOptions();
	     options.setImageType(ImageType.PNG);
	     ws.getPageSetup().setPaperSize(PaperSizeType.PAPER_A_4);
	     ws.getPageSetup().setPrintGridlines(true);
	     
	     //CellArea[] pageBreaks = ws.getPrintingPageBreaks(options);
	     
	     SheetRender sr = new SheetRender(ws, options);
	     
	     for (int k = 0; k < sr.getPageCount(); k++)
         {
            	 sr.toImage(k, "f:\\files\\out1"+k+".png");
          
         }

Hope, this helps a bit.

@Amjad_Sahi
Thanks for the quick response.

Yes, We’ve tried this earlier and it has worked without any issues.
But for some functional reasons, we want the document to be rendered based on the print area.
So, the solution you have proposed will not be feasible for us.
Can you please look at it again?

@askgowda,

Alright, as I have already reproduced the issue and the workaround proposed may not work well for your needs, I have logged a ticket with an id “CELLSJAVA-43015” for your issue. We will investigate and look into it soon.

Once we have an update on it or we figure it out, we will let you know.

@Amjad_Sahi
Thank you

The issues you have found earlier (filed as CELLSJAVA-43015) have been fixed in this update.