I am trying to convert the named range into an image using the SheetRender API and setting the printArea on the pageSetup of the sheet that contains the data of the namedRange (Excel_Table) using the below mentioned code:
Workbook wb = new Workbook(“file.xlsx”);
Worksheet sheet = wb.getWorksheets().get(1); // The first sheet has the named range that I want converted to image.
PageSetup setup = sheet.getPageSetup();
setupCopiedSheet.setPrintArea(“A8:H50”); // the named range Excel_Table is contained within this range
ImageOrPrintOptions imgOrPrintOptions = new ImageOrPrintOptions();
imgOrPrintOptions.setOnePagePerSheet(true); // otherwise wider ranges don’t fit
new SheetRender(sheet_copied, imgOrPrintOptions).toImage(0, byOut);
byOut.toByteArray(); // this array represents the image.
What I want to know is if there is a way to compress this image o that it takes less disk space without ruining the quality?
Also, when I do not set the resolution and use the default value of 96, the dimension of the image generated is smaller than what is generated using a resolution setting of 300. How do I fix the size of the image so that it is within the bounds I can specify but also generates an image of high resolution?
I tried using imageOrPrintOptions.setDesiredSize(int width, int height), but that impacts the final resolution, and the picture is not as clear as I would want it to be.
I have attached the following files with this post:
- ReferenceDoclet_withSingleCell.zip-- has the excel file that has the named range
- Excel_Table_fonts.png – the image generated with horizontal and vertical resolution set as 300. This image is too big (the width/height are too big)
- Excel_Table_fonts_withSizeSet.png – the image that i generated with resolution set as 300, but I also set desired size as the total width/height of the columns/rows contained within the named range in pixels. The problem that I have with this image is that it’s not as clear, the resolution does not seem to be 300 which is what I set it to.
- Excel_Table_fonts_default.png – the image generated using default resolution of 96 and without setting the desired size.
Hope you can provide some help on how I can regulate the resolution and the dimension of the image that I am generating.