gpt4 book ai didi

java - 使用 iText 和 PdfGraphics2D 的 PPTX 到 PDF 错误

转载 作者:行者123 更新时间:2023-12-02 10:34:08 27 4
gpt4 key购买 nike

我正在尝试将 pptx 文件转换为图像,然后使用 apache poi 和 iText 创建 PDF。

Dimension pgsize = ppt.getPageSize();
XSLFSlide slide = ppt.getSlides()[0];
PdfWriter pdfWriter = null;
Document document = new Document()

pdfWriter = PdfWriter.getInstance(document, new FileOutputStream(targetPath));
document.setPageSize(new Rectangle((float) pgsize.getWidth(), (float) pgsize.getHeight()));
document.open();

PdfGraphics2D graphics = (PdfGraphics2D) pdfWriter.getDirectContent().createGraphics((float) pgsize.getWidth(),
(float) pgsize.getHeight());

slide.draw(graphics);
graphics.dispose();
document.close();

但我收到错误:

java.lang.AbstractMethodError: org.apache.poi.xslf.usermodel.XSLFTextRun.getFontInfo(Lorg/apache/poi/common/usermodel/fonts/FontGroup;)Lorg/apache/poi/common/usermodel/fonts/FontInfo;
at org.apache.poi.sl.draw.DrawTextParagraph.getAttributedString(DrawTextParagraph.java:584) ~[poi-3.17.jar:3.17]
at org.apache.poi.sl.draw.DrawTextParagraph.breakText(DrawTextParagraph.java:259) ~[poi-3.17.jar:3.17]
at org.apache.poi.sl.draw.DrawTextShape.drawParagraphs(DrawTextShape.java:156) ~[poi-3.17.jar:3.17]
at org.apache.poi.sl.draw.DrawTextShape.drawContent(DrawTextShape.java:125) ~[poi-3.17.jar:3.17]
at org.apache.poi.sl.draw.DrawSimpleShape.draw(DrawSimpleShape.java:97) ~[poi-3.17.jar:3.17]
at org.apache.poi.sl.draw.DrawSheet.draw(DrawSheet.java:71) ~[poi-3.17.jar:3.17]
at org.apache.poi.sl.draw.DrawSlide.draw(DrawSlide.java:41) ~[poi-3.17.jar:3.17]
at org.apache.poi.xslf.usermodel.XSLFSlide.draw(XSLFSlide.java:307) ~[tika-server-1.16.jar:1.16]

最佳答案

解决方案是不要混合 POI 版本。 Apache Tika 中已经有 POI

关于java - 使用 iText 和 PdfGraphics2D 的 PPTX 到 PDF 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53415615/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com