Page 1 of 1

CTGraphicFrame Problem when creating a chart

PostPosted: Thu Apr 14, 2011 1:03 pm
by compactMetric

Thanks for writing pptx4j! It's great to be able to create full-featured powerpoint presentations from Java!

I'm trying to create a presentation with a chart on it. However, I am getting the following exception:

- with linked exception:
[javax.xml.bind.JAXBException: class org.docx4j.dml.chartDrawing.CTGraphicFrame nor any of its super class is known to this context.]
at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(Unknown Source)
at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.marshal(Unknown Source)
at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(Unknown Source)
at ChartTest.make(
at ChartTest.main(

Here's the code:
Code: Select all
import java.util.List;

import javax.xml.bind.JAXBException;

import org.docx4j.dml.CTNonVisualDrawingProps;
import org.docx4j.dml.CTNonVisualGraphicFrameProperties;
import org.docx4j.dml.CTPoint2D;
import org.docx4j.dml.CTPositiveSize2D;
import org.docx4j.dml.CTTransform2D;
import org.docx4j.dml.chartDrawing.CTGraphicFrame;
import org.docx4j.dml.chartDrawing.CTGraphicFrameNonVisual;
import org.docx4j.openpackaging.packages.PresentationMLPackage;
import org.pptx4j.pml.CTExtension;
import org.pptx4j.pml.CTExtensionListModify;

public class ChartTest
   public static void main(String[] args)
      catch (Exception e)
         // TODO Auto-generated catch block
   public static void make() throws Exception {
        // Where will we save our new .ppxt?
        String outputfilepath = System.getProperty("user.dir") + "/ppt_chart_test1.pptx";

        // Create skeletal package
        PresentationMLPackage presentationMLPackage = PresentationMLPackage.createPackage();

        // Create and add a new slidepart to the presentation package
        // First get Main Presentation Part and add new slide to it
        MainPresentationPart mpPart = (MainPresentationPart) presentationMLPackage.getParts().getParts().get(
                new PartName("/ppt/presentation.xml"));
        SlidePart  slidePart = new SlidePart(new PartName("/ppt/slides/slide1.xml"));
        mpPart.addSlideIdListEntry( slidePart );
        slidePart.setJaxbElement( SlidePart.createSld() );

      // Get and set slide layout part target
      SlideLayoutPart layoutPart = (SlideLayoutPart) presentationMLPackage.getParts().getParts().get(
                   new PartName("/ppt/slideLayouts/slideLayout1.xml"));

        // Last add the shapes to the slide
        addShapesToSlide( slidePart);

        // All done: save it;

        System.out.println("\n\n done .. saved " + outputfilepath);
   private static void addShapesToSlide(SlidePart slidePart) throws JAXBException
      List<Object> listOfSpGrpSpEtc = slidePart.getJaxbElement().getCSld().getSpTree().getSpOrGrpSpOrGraphicFrame();

        CTGraphicFrame chartFrame = getCTGraphicFrame("Chart 1", 1524000, 1397000);
        slidePart.getJaxbElement().getCSld().getSpTree().setExtLst(new CTExtensionListModify());
        CTExtension ctExtension = new CTExtension();
   private static CTGraphicFrame getCTGraphicFrame(String name, int x, int y)
      CTGraphicFrame graphicFrame = new CTGraphicFrame();
      graphicFrame.setNvGraphicFramePr(new CTGraphicFrameNonVisual());
      graphicFrame.getNvGraphicFramePr().setCNvPr(new CTNonVisualDrawingProps());
      graphicFrame.getNvGraphicFramePr().setCNvGraphicFramePr(new CTNonVisualGraphicFrameProperties());
      CTTransform2D ctTransform2D = new CTTransform2D();
      CTPoint2D ctPoint2D = new CTPoint2D();
      CTPositiveSize2D ctPositiveSize2D = new CTPositiveSize2D();
      return graphicFrame;

Any ideas?

Re: CTGraphicFrame Problem when creating a chart

PostPosted: Thu Apr 14, 2011 10:15 pm
by jason
It works following

Thanks for providing the sample with your post; that made this easy to fix. :-)

Are you comfortable building from source, or would you like me to make a nightly build containing this patch?

cheers .. Jason

Re: CTGraphicFrame Problem when creating a chart

PostPosted: Fri Apr 15, 2011 9:47 am
by compactMetric
Thanks. I'll try to compile from source.

Re: CTGraphicFrame Problem when creating a chart

PostPosted: Fri Apr 15, 2011 11:09 am
by compactMetric
So I'm having trouble compiling from source. Could you jar-up a nightly build?

Thanks for your help!

Re: CTGraphicFrame Problem when creating a chart

PostPosted: Sun Apr 17, 2011 1:39 am
by jason
Please see ... 110416.jar

What was the problem compiling from source?

Re: CTGraphicFrame Problem when creating a chart

PostPosted: Mon Apr 18, 2011 1:03 pm
by compactMetric

I think I didn't configure Maven correctly. It would run without errors, but it wouldn't generate any .class files. Not a big deal though. Thanks for the nightly build.