Search code examples
javaapache-poiliferay-6xslf

ERROR : Caused by: java.lang.IllegalArgumentException: Relationship null doesn't start with this part /ppt/slides/slide3.xml


I'm working with apache poi xslf to export ppt file. First, I have a template set with 3 slides : title slide, summary slide, and third slide

I duplicate the 3rd slide (i have it as a template) in order to copy many data/graphics as I have in database.

So in order to do that :

XMLSlideShow slideShow = new XMLSlideShow(dlfile.getContentStream());
XSLFSlide[] slides = slideShow.getSlides();
XSLFSlide createdSlide = slideShow.createSlide(slides[2].getSlideLayout());
//get content from slide to createdslide
createdSlide.importContent(slides[2]); 
//... add data to created slide

I have an error at line : createdSlide.importContent(slides[2]);

Caused by: java.lang.IllegalArgumentException: Relationship null doesn't start with this part /ppt/slides/slide3.xml
    at org.apache.poi.openxml4j.opc.PackagePart.getRelatedPart(PackagePart.java:468)
    at org.apache.poi.xslf.usermodel.XSLFSheet.importBlip(XSLFSheet.java:521)
    at org.apache.poi.xslf.usermodel.XSLFSlide.importContent(XSLFSlide.java:235)

P.S : this code works just fine with another tempalte. I need to use different templates based on user selection. (templates are stored in db as i'm using liferay).

I've searched for hours, but in vain! I don't even understand what the error means.

Any links/help would appreciated.


Solution

  • The error comes from org.apache.poi.openxml4j.opc.PackagePart.getRelatedPart code line 468:

    throw new IllegalArgumentException("Relationship " + rel + " doesn't start with this part " + _partName);.

    The error states that rel is null. So org.apache.poi.xslf.usermodel.XSLFSheet.importBlip in code line 521:

    blipPart = packagePart.getRelatedPart(blipRel);

    had handed over blipRelas null. So org.apache.poi.xslf.usermodel.XSLFSlide.importContent in code line 235:

    String relId = importBlip(blipId, src.getPackagePart());

    had handed over blipId as null.

    This is pretty clear if one of the pictures in your template in Slide 3 is not an embedded picture but a linked picture. The code:

    @Override
    public XSLFSlide importContent(XSLFSheet src){
        super.importContent(src);
    
        XSLFBackground bgShape = getBackground();
        if(bgShape != null) {
            CTBackground bg = (CTBackground)bgShape.getXmlObject();
            if(bg.isSetBgPr() && bg.getBgPr().isSetBlipFill()){
                CTBlip blip = bg.getBgPr().getBlipFill().getBlip();
                String blipId = blip.getEmbed();
    
                String relId = importBlip(blipId, src.getPackagePart());
                blip.setEmbed(relId);
            }
        }
        return this;
    }
    

    consideres only embedded blip data.

    From your code lines I can see that you are using apache poi version 3.9. But as far as I see in current versions this had not changed until now. Only embedded bilp data will be considered.

    So have a look at your template and make sure that all pictures are embedded and not linked.