V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
RedBeanIce
V2EX  ›  Java

Poi PPT PPTX 处理 [生产环境使用]

  •  
  •   RedBeanIce · 2020-08-27 21:19:07 +08:00 · 1582 次点击
    这是一个创建于 1309 天前的主题,其中的信息可能已经有所发展或是发生改变。

    poi 在 PPT 转成图片的时候,PPT 会有很多复杂的东西,导致解析困难

    如以下复杂结构:

    1,文本框套文本框套文本框,嵌套文字

    2,文本框嵌套图片

    等等。。。。

    求助各位大佬,如何解析复杂的结构,让我可以将一页 PPT 转成图片

    11 条回复    2020-08-28 14:32:39 +08:00
    PopRain
        1
    PopRain  
       2020-08-27 21:47:28 +08:00
    方向错了吧,你要去自己渲染 PPT? 这个难度太高了,换个方法吧
    iseki
        2
    iseki  
       2020-08-27 21:48:53 +08:00
    自己渲染 PPT 意味着你要把 Office 的很大一部分内容自己做一遍(换个办法吧
    PopRain
        3
    PopRain  
       2020-08-27 21:59:42 +08:00
    stackoverflow 搜索 PPT to PNG conversion with Apache POI

    发链接要手机号验证。。。。
    RedBeanIce
        4
    RedBeanIce  
    OP
       2020-08-27 22:04:54 +08:00
    @PopRain
    @iseki
    #1
    #2
    只是将 PPT 转成图片,只是在转的时候,poi 解析复杂结构,解不了。
    图片上不会显示,
    PopRain
        5
    PopRain  
       2020-08-27 22:11:40 +08:00
    那是不是需要用 Spire 之类的商业 SDK 了,可以用试用版先试试
    340244120w
        6
    340244120w  
       2020-08-28 09:16:20 +08:00
    推荐 aspose 系列
    519718366
        7
    519718366  
       2020-08-28 10:23:54 +08:00
    http://poi.apache.org/slideshow/how-to-shapes.html#Render

    HSLF provides a way to export slides into images. You can capture slides into java.awt.Graphics2D object (or any other) and serialize it into a PNG or JPEG format. Please note, although HSLF attempts to render slides as close to PowerPoint as possible, the output may look differently from PowerPoint due to the following reasons:

    - Java2D renders fonts differently vs PowerPoint. There are always some differences in the way the font glyphs are painted
    - HSLF uses java.awt.font.LineBreakMeasurer to break text into lines. PowerPoint may do it in a different way.
    - If a font from the presentation is not available, then the JDK default font will be used.

    Current Limitations:
    - Some types of shapes are not yet supported (WordArt, complex auto-shapes)
    - Only Bitmap images (PNG, JPEG, DIB) can be rendered in Java

    或许是真的不能支持这些复杂的妖魔鬼怪 PPT 吧。
    DsuineGP
        8
    DsuineGP  
       2020-08-28 10:31:01 +08:00
    前几天还在调研 libreoffice 的 cli,一条命令就能转,还开源,强烈推荐。poi 不适合做 ppt 和 word 解析,因为渲染逻辑太复杂了。楼上说的 aspose 也还行。
    RedBeanIce
        9
    RedBeanIce  
    OP
       2020-08-28 10:36:58 +08:00
    @PopRain
    我先去试试免费的,哭。
    RedBeanIce
        10
    RedBeanIce  
    OP
       2020-08-28 10:38:22 +08:00
    @340244120w #6
    !!!我去试试,都可以试验!!
    @519718366 #7
    @DsuineGP #8
    收到,,看来我只能尝试多种方案了,,一样样试过去,看哪种能够解决我这个问题。自己写不现实了。
    RedBeanIce
        11
    RedBeanIce  
    OP
       2020-08-28 14:32:39 +08:00
    @DsuineGP

    #8 尝试了一下 LibreOffice_6.4.6_Win_x64 命令行,Windows 下 会出现字是横着的,但是变成了竖着的。尴尬
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2700 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 15:35 · PVG 23:35 · LAX 08:35 · JFK 11:35
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.