Java ppt转图片部署到Linux 乱码

原因:linux不支持宋体

解决:

1.下载 simsun.ttf文件

链接: https://pan.baidu.com/s/1fLE-m1ZL5YivIa1_YbUuIw

提取码: 625y 

2.将文件上传至Linux指定目录下 /usr/share/fonts

新建自定义字体目录:mkdir myfonts

3.在这个目录下执行命令

mkfontscale
mkfontdir
fc-cache -fv

4.重启项目查看效果

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
JavaPpt图片是指使用Java编程语言将PPT文件换为图片的过程。通过Java提供的相关库和API,可以实现将PPT文件中的每一页内容换为对应的图片文件。 在Java中,可以使用Apache POI库来读取PPT文件的内容,并使用Java图形库(如Java AWT或JavaFX)将每一页的内容渲染为图片。具体步骤如下: 1. 导入Apache POI库和Java图形库的相关依赖。 2. 使用Apache POI库加载PPT文件,获取每一页的内容。 3. 创建一个空白的图片对象,设置图片的宽度和高度。 4. 使用Java图形库将每一页的内容绘制到图片上。 5. 将生成图片保存到指定的路径。 以下是一个简单的示例代码,演示了如何使用JavaPPT文件换为图片: ```java import org.apache.poi.xslf.usermodel.XMLSlideShow; import org.apache.poi.xslf.usermodel.XSLFSlide; import java.awt.Dimension; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import javax.imageio.ImageIO; public class PptToImageConverter { public static void main(String[] args) { String pptFilePath = "path/to/presentation.pptx"; String outputFolderPath = "path/to/output/folder/"; try { // Load the PPT file XMLSlideShow ppt = new XMLSlideShow(new FileInputStream(pptFilePath)); // Get the dimensions of the slides Dimension slideSize = ppt.getPageSize(); // Iterate through each slide int slideNumber = 1; for (XSLFSlide slide : ppt.getSlides()) { // Create a blank image with the same dimensions as the slide BufferedImage image = new BufferedImage(slideSize.width, slideSize.height, BufferedImage.TYPE_INT_RGB); // Render the slide onto the image Graphics2D graphics = image.createGraphics(); slide.draw(graphics); // Save the image to a file String outputFilePath = outputFolderPath + "slide" + slideNumber + ".png"; ImageIO.write(image, "png", new FileOutputStream(outputFilePath)); // Increment the slide number slideNumber++; } System.out.println("PPT to image conversion completed."); } catch (IOException e) { e.printStackTrace(); } } } ``` 请注意,上述示例代码中使用的是Apache POI库的XSLF模块,适用于PPTX格式的文件。如果需要处理PPT格式的文件,可以使用HSLF模块。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值