Aspose.Slides

//Instantiate a Presentation object that represents a presentation file
Presentation pres = new Presentation("data/pptx4j/presentation.pptx");

//Accessing slides
for (ISlide slide : pres.getSlides())
{
	System.out.println(slide.getSlideNumber());			
}

PPTX4J

try
{
	getInputFilePath(args);
}
catch (IllegalArgumentException e)
{
	inputfilepath = "data/pptx4j/pptx-basic.xml";
}

PresentationMLPackage pMLPackage = (PresentationMLPackage) OpcPackage
		.load(new java.io.File(inputfilepath));

SlidePart slide = (SlidePart) pMLPackage.getParts().get(
		new PartName("/ppt/slides/slide1.xml"));

new TraversalUtil(slide.getJaxbElement().getCSld().getSpTree()
		.getSpOrGrpSpOrGraphicFrame(),

new Callback()
{

	String indent = "";

	// @Override
	public List<Object> apply(Object o)
	{

		String text = "";

		try
		{
			System.out.println(indent
					+ o.getClass().getName()
					+ "\n\n"
					+ XmlUtils.marshaltoString(o, true,
							org.pptx4j.jaxb.Context.jcPML));
		}
		catch (RuntimeException me)
		{
			System.out.println(indent + o.getClass().getName());
		}

		if (o instanceof org.pptx4j.pml.Shape)
		{
			CTTextBody txBody = ((org.pptx4j.pml.Shape) o).getTxBody();
			if (txBody != null)
			{
				for (CTTextParagraph tp : txBody.getP())
				{

					System.out.println(indent
							+ tp.getClass().getName()
							+ "\n\n"
							+ XmlUtils
									.marshaltoString(
											tp,
											true,
											true,
											org.pptx4j.jaxb.Context.jcPML,
											"http://schemas.openxmlformats.org/presentationml/2006/main",
											"txBody",
											CTTextParagraph.class));

				}
			}
		}

		return null;
	}

	// @Override
	public boolean shouldTraverse(Object o)
	{
		return true;
	}

	// Depth first
	// @Override
	public void walkJAXBElements(Object parent)
	{

		indent += "    ";

		List children = getChildren(parent);
		if (children != null)
		{

			for (Object o : children)
			{

				// if its wrapped in javax.xml.bind.JAXBElement, get its
				// value
				o = XmlUtils.unwrap(o);

				this.apply(o);

				if (this.shouldTraverse(o))
				{
					walkJAXBElements(o);
				}

			}
		}

		indent = indent.substring(0, indent.length() - 4);
	}

	// @Override
	public List<Object> getChildren(Object o)
	{
		return TraversalUtil.getChildrenImpl(o);
	}

}

);

Download Source Code

For More Examples, Please Visit Aspose Docs

Last edited Aug 19, 2014 at 11:42 AM by shoaibkhan, version 2