aboutsummaryrefslogtreecommitdiffstats
path: root/src/examples
diff options
context:
space:
mode:
authorYegor Kozlov <yegor@apache.org>2011-11-07 09:12:16 +0000
committerYegor Kozlov <yegor@apache.org>2011-11-07 09:12:16 +0000
commitde14b40a970a2626701f59f1ccfa3b6970614519 (patch)
treec69669a55694ec94fa04fb396000a58287cd6af2 /src/examples
parentd6093ba1e32730932b950a93f7ebd9aeba20a370 (diff)
downloadpoi-de14b40a970a2626701f59f1ccfa3b6970614519.tar.gz
poi-de14b40a970a2626701f59f1ccfa3b6970614519.zip
more progress with xlsf: support for gradient and texture fills, backgrounds, improved drawing of preset shapes and many more updates ...
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1198658 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/examples')
-rw-r--r--src/examples/src/org/apache/poi/xslf/usermodel/tutorial/Step1.java68
-rw-r--r--src/examples/src/org/apache/poi/xslf/usermodel/tutorial/Step2.java80
2 files changed, 148 insertions, 0 deletions
diff --git a/src/examples/src/org/apache/poi/xslf/usermodel/tutorial/Step1.java b/src/examples/src/org/apache/poi/xslf/usermodel/tutorial/Step1.java
new file mode 100644
index 0000000000..a83a17e4b8
--- /dev/null
+++ b/src/examples/src/org/apache/poi/xslf/usermodel/tutorial/Step1.java
@@ -0,0 +1,68 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.poi.xslf.usermodel.tutorial;
+
+import org.apache.poi.xslf.usermodel.XMLSlideShow;
+import org.apache.poi.xslf.usermodel.XSLFShape;
+import org.apache.poi.xslf.usermodel.XSLFSlide;
+import org.apache.poi.xslf.usermodel.XSLFTextParagraph;
+import org.apache.poi.xslf.usermodel.XSLFTextRun;
+import org.apache.poi.xslf.usermodel.XSLFTextShape;
+
+import java.io.FileInputStream;
+
+/**
+ * Reading a .pptx presentation and printing basic shape properties
+ *
+ * @author Yegor Kozlov
+ */
+public class Step1 {
+
+ public static void main(String[] args) throws Exception {
+ if(args.length == 0) {
+ System.out.println("Input file is required");
+ return;
+ }
+
+ XMLSlideShow ppt = new XMLSlideShow(new FileInputStream(args[0]));
+
+ for(XSLFSlide slide : ppt.getSlides()){
+ System.out.println("Title: " + slide.getTitle());
+
+ for(XSLFShape shape : slide.getShapes()){
+ if(shape instanceof XSLFTextShape) {
+ XSLFTextShape tsh = (XSLFTextShape)shape;
+ for(XSLFTextParagraph p : tsh){
+ System.out.println("Paragraph level: " + p.getLevel());
+ for(XSLFTextRun r : p){
+ System.out.println(r.getText());
+ System.out.println(" bold: " + r.isBold());
+ System.out.println(" italic: " + r.isItalic());
+ System.out.println(" underline: " + r.isUnderline());
+ System.out.println(" font.family: " + r.getFontFamily());
+ System.out.println(" font.size: " + r.getFontSize());
+ System.out.println(" font.color: " + r.getFontColor());
+ }
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/src/examples/src/org/apache/poi/xslf/usermodel/tutorial/Step2.java b/src/examples/src/org/apache/poi/xslf/usermodel/tutorial/Step2.java
new file mode 100644
index 0000000000..16b155d3f2
--- /dev/null
+++ b/src/examples/src/org/apache/poi/xslf/usermodel/tutorial/Step2.java
@@ -0,0 +1,80 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.poi.xslf.usermodel.tutorial;
+
+import org.apache.poi.xslf.usermodel.SlideLayout;
+import org.apache.poi.xslf.usermodel.XMLSlideShow;
+import org.apache.poi.xslf.usermodel.XSLFSlide;
+import org.apache.poi.xslf.usermodel.XSLFSlideLayout;
+import org.apache.poi.xslf.usermodel.XSLFSlideMaster;
+import org.apache.poi.xslf.usermodel.XSLFTextShape;
+
+import java.io.FileOutputStream;
+
+/**
+ * Create slides from pre-defined slide layouts
+ *
+ * @author Yegor Kozlov
+ */
+public class Step2 {
+ public static void main(String[] args) throws Exception{
+ XMLSlideShow ppt = new XMLSlideShow();
+
+
+ // first see what slide layouts are available by default
+ System.out.println("Available slide layouts:");
+ for(XSLFSlideMaster master : ppt.getSlideMasters()){
+ for(XSLFSlideLayout layout : master.getSlideLayouts()){
+ System.out.println(layout.getType());
+ }
+ }
+
+ // blank slide
+ XSLFSlide blankSlide = ppt.createSlide();
+
+ XSLFSlideMaster defaultMaster = ppt.getSlideMasters()[0];
+
+ // title slide
+ XSLFSlideLayout titleLayout = defaultMaster.getLayout(SlideLayout.TITLE);
+ XSLFSlide slide1 = ppt.createSlide(titleLayout);
+ XSLFTextShape title1 = slide1.getPlaceholder(0);
+ title1.setText("First Title");
+
+ // title and content
+ XSLFSlideLayout titleBodyLayout = defaultMaster.getLayout(SlideLayout.TITLE_AND_CONTENT);
+ XSLFSlide slide2 = ppt.createSlide(titleBodyLayout);
+
+ XSLFTextShape title2 = slide2.getPlaceholder(0);
+ title2.setText("Second Title");
+
+ XSLFTextShape body2 = slide2.getPlaceholder(1);
+ body2.clearText(); // unset any existing text
+ body2.addNewTextParagraph().addNewTextRun().setText("First paragraph");
+ body2.addNewTextParagraph().addNewTextRun().setText("Second paragraph");
+ body2.addNewTextParagraph().addNewTextRun().setText("Third paragraph");
+
+
+
+ FileOutputStream out = new FileOutputStream("step2.pptx");
+ ppt.write(out);
+ out.close();
+
+ }
+}