Search code examples
javaapacheitextapache-poiapache-tika

PPTX to PDF error using iText and PdfGraphics2D


I am trying to convert a pptx file to an Image and then create a PDF from it using apache poi and iText.

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();

But I get the error:

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]

Solution

  • Solution was to not mix POI versions. Apache Tika already had POI in it