views:

375

answers:

1

Hi all,

I got a problem when I try to use Apache POI project to convert my PPT to Images.My code as follows:

FileInputStream is = new FileInputStream("test.ppt");

SlideShow ppt = new SlideShow(is);


is.close();

Dimension pgsize = ppt.getPageSize();

Slide[] slide = ppt.getSlides();

for (int i = 0; i < slide.length; i++) {

BufferedImage img = new BufferedImage(pgsize.width, pgsize.height,
BufferedImage.TYPE_INT_RGB);
Graphics2D graphics = img.createGraphics();
//clear the drawing area
graphics.setPaint(Color.white);
graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height));

//render
slide[i].draw(graphics);

//save the output
FileOutputStream out = new FileOutputStream("slide-" + (i+1) + ".png");
javax.imageio.ImageIO.write(img, "png", out);
out.close();

It works fine except that all Chinese words are converted to some squares.The png image I got is like following image: alt text Then how can I fix this?Thanks in advance!

+1  A: 

The issue is usage of FileOuputStream which will always write data to the file in default system encoding which is most probably ISO-8859_1 for Windows. Chinese characters are not supported by this encoding. You need to create a stream where you can write using UTF-8 encoding which needs creation of reader. I was looking at the API but did not find any methods taking reader as an argument. But check if ImageOutputStream can help you.

Fazal
I'll check that,thank you.
SpawnCxy