Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   *  Copyright 2010, Plutext Pty Ltd.
   *   
   *  This file is part of docx4j.
  
      docx4j is licensed under the Apache License, Version 2.0 (the "License"); 
      you may not use this file except in compliance with the License. 
  
      You may obtain a copy of the License at 
 
         http://www.apache.org/licenses/LICENSE-2.0 
 
     Unless required by applicable law or agreed to in writing, software 
     distributed under the License is distributed on an "AS IS" BASIS, 
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
     See the License for the specific language governing permissions and 
     limitations under the License.
 
  */
 
 package org.docx4j.openpackaging.packages;
 
 
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
 

Author(s):
jharrop
 
 public class PresentationMLPackage  extends OpcPackage {
 	
 	protected static Logger log = LoggerFactory.getLogger(PresentationMLPackage.class);


Constructor. Also creates a new content type manager
 	
 	public PresentationMLPackage() {
 		super();
 	}
Constructor.

Parameters:
contentTypeManager The content type manager to use
 
 	public PresentationMLPackage(ContentTypeManager contentTypeManager) {
 		super(contentTypeManager);
 	}


Convenience method to create a PresentationMLPackage from an existing File (.pptx or .xml Flat OPC).

Parameters:
pptxFile The pptx file
	public static PresentationMLPackage load(java.io.File pptxFilethrows Docx4JException {
		return (PresentationMLPackage)OpcPackage.load(pptxFile);
	}
	public boolean setPartShortcut(Part partString relationshipType) {
		if (relationshipType.equals(.)) {
			.info("Set shortcut for docPropsCorePart");
			return true;			
else if (relationshipType.equals(.)) {
			.info("Set shortcut for docPropsExtendedPart");
			return true;			
else if (relationshipType.equals(.)) {
			.info("Set shortcut for docPropsCustomPart");
			return true;			
else if (relationshipType.equals(.)) {
			.info("Set shortcut for mainPresentationPart");
			return true;			
else {	
			return false;
		}
	}
	}

Create an empty presentation.

		String slideSize= Docx4jProperties.getProperties().getProperty("pptx4j.PageSize""A4");
		.info("Using paper size: " + slideSize);
		boolean landscape= Docx4jProperties.getProperty("pptx4j.PageOrientationLandscape"true);
		.info("Landscape orientation: " + landscape);
				SlideSizesWellKnown.valueOf(slideSize), landscape); 
	}

Create an empty presentation.

			boolean landscapethrows InvalidFormatException {
		// Create a package
		// Presentation part
		try {
			pp = new MainPresentationPart();
					MainPresentationPart.createJaxbPresentationElement(szlandscape) );
			pmlPack.addTargetPart(pp);		
//			// Slide part
//			SlidePart slidePart = new SlidePart();
//			pp.addSlideIdListEntry(slidePart);
//
//			slidePart.setJaxbElement( SlidePart.createSld() );
			// Slide layout part
			SlideLayoutPart layoutPart = new SlideLayoutPart(); 
			layoutPart.setJaxbElement( SlideLayoutPart.createSldLayout() );
//			slidePart.addTargetPart(layoutPart);
			// Slide Master part
			SlideMasterPart masterPart = new SlideMasterPart();
			masterPart.setJaxbElement(masterPart.createSldMaster() );
			masterPart.addSlideLayoutIdListEntry(layoutPart);
			layoutPart.addTargetPart(masterPart);
			// Theme part
			ThemePart themePart = new ThemePart(new PartName("/ppt/theme/theme1.xml"));
			java.io.InputStream is = org.docx4j.utils.ResourceUtils.getResource(
						"org/docx4j/openpackaging/parts/PresentationML/theme.xml");
			themePart.unmarshal(is);
			// .. add it in 2 places ..
			masterPart.addTargetPart(themePart);
			pp.addTargetPart(themePart);
catch (Exception e) {
			throw new InvalidFormatException("Couldn't create package"e);
		}
		// Return the new package
		return pmlPack;
	}

Create a slide and add it to the package. Deprecated, so use MainPresentationPart's addSlide method instead.

Parameters:
pp
layoutPart
partName
Returns:
the slide
Throws:
org.docx4j.openpackaging.exceptions.InvalidFormatException
javax.xml.bind.JAXBException
	public static SlidePart createSlidePart(MainPresentationPart ppSlideLayoutPart layoutPartPartName partName
		// Slide part
		SlidePart slidePart = new SlidePart(partName);
		pp.addSlideIdListEntry(slidePart);
		slidePart.setJaxbElement( SlidePart.createSld() );
		// Slide layout part
		slidePart.addTargetPart(layoutPart);
		return slidePart;
	}
  
Create a notes slide and add it to slide relationships

Parameters:
sourcePart
partName
Returns:
the notes slide
Throws:
org.docx4j.openpackaging.exceptions.InvalidFormatException
javax.xml.bind.JAXBException
	public static NotesSlidePart createNotesSlidePart(Part sourcePartPartName partNamethrows Exception {
        String proposedRelId = sourcePart.getRelationshipsPart().getNextId();
        NotesSlidePart notesSlidePart = new NotesSlidePart(partName);
        notesSlidePart.getSourceRelationships().add(sourcePart.addTargetPart(notesSlidePartproposedRelId));
        notesSlidePart.setJaxbElement(NotesSlidePart.createNotes());
        return notesSlidePart;
    }
	private static String SAMPLE_SHAPE = 			
		"<p:sp   xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:p=\"http://schemas.openxmlformats.org/presentationml/2006/main\">"
"<p:nvSpPr>"
"<p:cNvPr id=\"4\" name=\"Title 3\" />"
"<p:cNvSpPr>"
"<a:spLocks noGrp=\"1\" />"
"</p:cNvSpPr>"
"<p:nvPr>"
"<p:ph type=\"title\" />"
"</p:nvPr>"
"</p:nvSpPr>"
"<p:spPr />"
"<p:txBody>"
"<a:bodyPr />"
"<a:lstStyle />"
"<a:p>"
"<a:r>"
"<a:rPr lang=\"en-US\" smtClean=\"0\" />"
"<a:t>Hello World</a:t>"
"</a:r>"
"<a:endParaRPr lang=\"en-US\" />"
"</a:p>"
"</p:txBody>"
"</p:sp>";
		if (!=null) {
		}
		// All this for the 16 possible things defined in STPlaceholderType!
		Map<StringShapeWrapperglobalPlaceHolders = new HashMap<StringShapeWrapper>();
		Iterator partIterator = this.getParts().getParts().entrySet().iterator();
	    while (partIterator.hasNext()) {
	    	
	        Map.Entry pairs = (Map.Entry)partIterator.next();
	        
	        Part p = (Part)pairs.getValue();
	        if (p instanceof SlideLayoutPart) {
	        	SldLayout sldLayout = ((SlideLayoutPart)p).getJaxbElement();	        	
	        	globalPlaceHolders.putAll( ((SlideLayoutPart)p).getIndexedPlaceHolders()  );
	        }
	    }
	    return globalPlaceHolders;
	}
		if (==null) {
			List<Stylestyles = TextStyles.generateStyles(this);
			Set<Stringlist = new HashSet<String>();			
			Map<StringStylemap = new HashMap<StringStyle>();
			for (Style s : styles) {
				map.put(s.getStyleId(), s);
				list.add(s.getStyleId());
			}
			 = new StyleTree(listmap);
				// TODO: We don't have defaultParagraphStyleId, defaultCharacterStyleId
				// so use DocDefaults for now.
		}
		return ;
	}
	public static void main(String[] argsthrows Exception {
		String inputfilepath = System.getProperty("user.dir") + "/sample-docs/pptx/pptx-basic.xml";
		PresentationMLPackage presentationMLPackage = 
			(PresentationMLPackage)PresentationMLPackage.load(new java.io.File(inputfilepath));		
//		ThemePart tp = (ThemePart)presentationMLPackage.getParts().getParts().get(
//				new PartName("/ppt/theme/theme1.xml"));
//		FontScheme fontScheme = tp.getFontScheme();
//		List<Style> styles = new ArrayList<Style>();
//		
//		// presentation.xml
//		MainPresentationPart pp = (MainPresentationPart)presentationMLPackage.getParts().getParts().get(
//				new PartName("/ppt/presentation.xml"));
//		styles.addAll(
//				TextStyles.generateWordStylesFromPresentationPart(
//						pp.getJaxbElement().getDefaultTextStyle(),
//						"", fontScheme));
//
//		// master
//		SlideMasterPart master = (SlideMasterPart)presentationMLPackage.getParts().getParts().get(
//				new PartName("/ppt/slideMasters/slideMaster1.xml"));
//		styles.addAll(
//				TextStyles.generateWordStylesForMaster(
//						master.getJaxbElement().getTxStyles(), 
//						1, fontScheme));
		Iterator partIterator = presentationMLPackage.getParts().getParts().entrySet().iterator();
	    while (partIterator.hasNext()) {
	    	
	        Map.Entry pairs = (Map.Entry)partIterator.next();
	        
	        Part p = (Part)pairs.getValue();
	        if (p instanceof SlidePart) {
//	        	ResolvedLayout rl = ((SlidePart)p).getResolvedLayout();		        	
//	        	System.out.println( XmlUtils.marshaltoString(rl.getShapeTree(), false, true, Context.jcPML,
//	        			"http://schemas.openxmlformats.org/presentationml/2006/main", "spTree", GroupShape.class) );
	        	
	        	..println(
	        			SvgExporter.svg(presentationMLPackage, (SlidePart)p)
	        			);
	        }
	    }
//		System.out.println(presentationMLPackage.getParts().getParts().size());
//		Map<String, ShapeWrapper> index = ShapeWrapper.indexPlaceHolders(	presentationMLPackage.getParts().getParts());
//		
//		SlidePart slidePart = (SlidePart)presentationMLPackage.getParts().getParts().get(
//				new PartName("/ppt/slides/slide1.xml"));
//
//		GroupShape shapeTree = slidePart.getEffectiveShapeTree( index );
//		
//		System.out.println( XmlUtils.marshaltoString(shapeTree, true, Context.jcPML));
		..println("\n\n done .. \n\n");
	}	
New to GrepCode? Check out our FAQ X