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

Free Support Forum - aspose.com

Fail in method toImage

When I run the createImage method in a Windows enviroment, it works perfectly. But, when I run it on Linux Red Hat 5.10, some part of the image is cut off. I googled it, but I didn’t find any solution.

---------------------------------------------------------------------------------------------------
public void createImage(byte[] input) throws Exception {

Workbook book = new Workbook(new ByteArrayInputStream(input));
Style defaultStyle = book.getDefaultStyle();
defaultStyle.getFont().setSize(9);
book.setDefaultStyle(defaultStyle);
WorksheetCollection sheets = book.getWorksheets();
ByteArrayOutputStream baos= null;

try
{
Worksheet sheet = sheets.get(0);

//alterar o formato da página para A4 e remover as margens
PageSetup pageSetup = sheet.getPageSetup();
pageSetup.setPaperSize(PaperSizeType.PAPER_A_4);
pageSetup.setOrientation(PageOrientationType.LANDSCAPE);
pageSetup.setTopMargin(0);
pageSetup.setBottomMargin(0);
pageSetup.setLeftMargin(0);
pageSetup.setRightMargin(0);
pageSetup.setZoom(100);


ImageOrPrintOptions imgOptionsPng = getImagePrint();
SheetRender srPng = new SheetRender(sheet, imgOptionsPng);

srPng.toImage(0, “test.jpg”);

}
finally
{
if (baos != null)
{
baos.flush();
baos.close();
}
}
}

private ImageOrPrintOptions getImagePrint() {
ImageOrPrintOptions imgOptionsPng = new ImageOrPrintOptions();
imgOptionsPng.setImageFormat(ImageFormat.getJpeg());
imgOptionsPng.setHorizontalResolution(300);
imgOptionsPng.setVerticalResolution(300);
imgOptionsPng.setQuality(100);
return imgOptionsPng;
}
---------------------------------------------------------------------------------------------------
I attached a example in this message.

Thanks,
Germano Souza




Hi Germano,


Thank you for contacting Aspose support.

We would first request you to give the latest version of Aspose.Cells for Java 8.2.1.3 a try on your end to observe any changes in the resultant image. In case the problem persists, we need the resultant image from Linux environment along with JDK version & type in use. We will try to simulate the exact environment to replicate the problem, and subsequently log it for correction purposes.

Unfortunately, this update didn’t solve the problem. Is there any other solution?

Thanks,
Germano Souza

Hi Germano,

Thanks for your posting and using Aspose.Cells.

If you just want to extract the image of your picture, then please try the following code on your Windows and Linux environment.

I have attached the output image generated by the code for your reference.

Java


String filePath = “F:\Shak-Data-RW\Downloads\example.xlsx”;


Workbook workbook = new Workbook(filePath);


Worksheet worksheet = workbook.getWorksheets().get(0);


Picture pic = worksheet.getPictures().get(0);


ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();

imgOptions.setImageFormat(ImageFormat.getJpeg());


pic.toImage(“output.jpg”, imgOptions);