poi 宋体_使用poi处理ppt 转为图片乱码问题解决

public int test(String source) {

FileInputStream is;

try {

is = new FileInputStream(source);

SlideShow ppt = new SlideShow(is);

is.close();

Slide[] slides = ppt.getSlides();

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

TextRun[] truns = slides[i].getTextRuns();

for ( int k=0;k

RichTextRun[] rtruns = truns[k].getRichTextRuns();

for(int l=0;l

int index = rtruns[l].getFontIndex();

String name = rtruns[l].getFontName();

rtruns[l].setFontIndex(1);

rtruns[l].setFontName("宋体");

}

}

Dimension pgsize = ppt.getPageSize();

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

slides[i].draw(graphics);

// save the output

FileOutputStream out = new FileOutputStream(

"e:\\pic\\test\\slide-" + (i + 1) + ".png");

javax.imageio.ImageIO.write(img, "png", out);

out.close();

}

} catch (Exception e) {

e.printStackTrace();

}

return 0;

}

其实就是字符问题,中文字符和西洋字符不能混用。这里把文本都改成了中文字符。

0

0

分享到:

2009-07-24 09:44

浏览 2733

评论


版权声明:本文为weixin_39849930原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。