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

Free Support Forum - aspose.com

There is some problem with toImage() method


I want to insert chart into PowerPoint presentation. First of all I have created a chart in Excel and that invoked a toImage() method to convert it to a picture. Then I added this picture to PP slide.
So, the toImage() are not working well. The appearance of an Excel chart and resulting picture is defferent. The category data text has a wrong alignment.

Could you help me?

There is a code to reproduce the problem:
private static String PATH = System.getProperty( “user.home” );
private static String categoryDataText = “Figur 1.2: Det samlede resultat for hver dimension sammenstillet med det valgte benchmark”;

public static void main( String[] args ) throws IOException
Workbook workbook = new Workbook();

Worksheet sheet = workbook.getWorksheets().getSheet( 0 );
sheet.setName( “Data” );

Cells cells = workbook.getWorksheets().getSheet( 0 ).getCells();
cells.getCell( “A2” ).setValue( “France” );
cells.getCell( “A3” ).setValue( “Germany” );
cells.getCell( “A4” ).setValue( “England” );
cells.getCell( “B2” ).setValue( 55000 );
cells.getCell( “B3” ).setValue( 70000 );
cells.getCell( “B4” ).setValue( 30000 );
cells.getCell( “A1” ).setValue( categoryDataText );

Chart aChart = sheet.getCharts().addChart( ChartType.BAR_CLUSTERED, 2, 2, 26, 11 );

NSeries nSeries = aChart.getNSeries();
createSeries( nSeries );

aChart.getNSeries().setCategoryData( “A1” );

aChart.getCategoryAxis().setRotation( 90 );
aChart.getCategoryAxis().getDisplayUnitLabel().setTextVerticalAlignment( TextAlignmentType.CENTER );

exportToPP( aChart );

private static void exportToPP( Chart aChart )
throws IOException
Presentation presentation = new Presentation( );
Slide slide = presentation.addEmptySlide();

ByteArrayOutputStream pictureBytes = new ByteArrayOutputStream();

ImageOptions imageOptions = new ImageOptions();
imageOptions.setImageFormat( ImageFormat.PNG );
imageOptions.setFashion( FileFormatType.EXCEL97TO2003 );

aChart.toImage( pictureBytes, imageOptions );

InputStream inputStream = new ByteArrayInputStream( pictureBytes.toByteArray() );

com.aspose.slides.Picture picture = new com.aspose.slides.Picture( presentation, inputStream );

int pictureId = presentation.getPictures().add( picture );

int pictureWidth = (int) (picture.getWidth() * 5.26);
int pictureHeight = (int) (picture.getHeight() * 5.26);

int slideWidth = slide.getBackground().getWidth();
int slideHeight = slide.getBackground().getHeight();

int pictureX = (slideWidth / 2) - (pictureWidth / 2);
int pictureY = (slideHeight / 2) - (pictureHeight / 2);

slide.getShapes().addPictureFrame( pictureId, pictureX, pictureY, pictureWidth, pictureHeight );

presentation.save( PATH + “sample.ppt”, SaveFormat.PPT );

private static void createSeries( NSeries nSeries )
ASeries as1 = nSeries.get( nSeries.add() );
as1.setValues( “B2” );

ASeries as2 = nSeries.get( nSeries.add() );
as2.setValues( “B3” );

ASeries as3 = nSeries.get( nSeries.add() );
as3.setValues( “B4” );

Dear Myryan,

Thanks for your interest in Aspose.Slides and Aspose.Cells.

I have tried to reproduce the issue as specified by you and feels that issue is related to Aspose.Cells because if I even generate the PNG image directly from Chart.toImage() method, I am encountering the same situation.

I will request Aspose.Cells team to provide you better technical assistance to resolve the issue.

We are sorry for your inconvenience,

Hi Mudassir.

Thank you for your reply.
I will be waiting for conclusion from Aspose.Cell team.
It’s a very important for our company.

Thanks in advance.


I am a representative of Aspose.Cells product family.

After an initial test, I can find the issue regarding Aspose.Cells for Java’s Chart 2 Image feature.
I have logged your issue into our issue tracking system with an id: CELLSJAVA-19239. We will figure your issue out soon.

I have also moved your thread to Aspose.Cells forum since it is an issue of our product.

Thank you.


Thank you for your reply. I will be waiting for resolve.

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

This message was posted using Notification2Forum from Downloads module by aspose.notifier.