aboutsummaryrefslogtreecommitdiffstats
path: root/src/scratchpad/examples
diff options
context:
space:
mode:
authorJosh Micich <josh@apache.org>2009-05-21 18:12:22 +0000
committerJosh Micich <josh@apache.org>2009-05-21 18:12:22 +0000
commit852e34bfea1affa39f4c89ed5edf2442b13708ab (patch)
treed0889907e5bd8eb66f27115444367eb49060c93a /src/scratchpad/examples
parent6e9212e8a2057badf8c0bc88433be602d8cc3ccd (diff)
downloadpoi-852e34bfea1affa39f4c89ed5edf2442b13708ab.tar.gz
poi-852e34bfea1affa39f4c89ed5edf2442b13708ab.zip
Changed CRLF to LF in scratchpad. Minor fixes for compiler warnings and formatting
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@777204 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/scratchpad/examples')
-rwxr-xr-xsrc/scratchpad/examples/src/org/apache/poi/hslf/examples/ApacheconEU08.java1033
-rw-r--r--src/scratchpad/examples/src/org/apache/poi/hslf/examples/BulletsDemo.java124
-rwxr-xr-xsrc/scratchpad/examples/src/org/apache/poi/hslf/examples/CreateHyperlink.java119
-rwxr-xr-xsrc/scratchpad/examples/src/org/apache/poi/hslf/examples/DataExtraction.java297
-rwxr-xr-xsrc/scratchpad/examples/src/org/apache/poi/hslf/examples/Graphics2DDemo.java160
-rw-r--r--src/scratchpad/examples/src/org/apache/poi/hslf/examples/Hyperlinks.java161
-rwxr-xr-xsrc/scratchpad/examples/src/org/apache/poi/hslf/examples/PPT2PNG.java215
-rwxr-xr-xsrc/scratchpad/examples/src/org/apache/poi/hslf/examples/TableDemo.java254
-rw-r--r--src/scratchpad/examples/src/org/apache/poi/hwpf/Word2Forrest.java5
9 files changed, 1183 insertions, 1185 deletions
diff --git a/src/scratchpad/examples/src/org/apache/poi/hslf/examples/ApacheconEU08.java b/src/scratchpad/examples/src/org/apache/poi/hslf/examples/ApacheconEU08.java
index 962349876a..91621339b4 100755
--- a/src/scratchpad/examples/src/org/apache/poi/hslf/examples/ApacheconEU08.java
+++ b/src/scratchpad/examples/src/org/apache/poi/hslf/examples/ApacheconEU08.java
@@ -1,517 +1,516 @@
-
-/* ====================================================================
- 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.hslf.examples;
-
-import org.apache.poi.hslf.usermodel.*;
-import org.apache.poi.hslf.model.*;
-import org.apache.poi.hslf.record.TextHeaderAtom;
-
-import java.io.IOException;
-import java.io.FileOutputStream;
-import java.io.File;
-import java.awt.*;
-
-/**
- * Presentation for Fast Feather Track on ApacheconEU 2008
- *
- * @author Yegor Kozlov
- */
-public class ApacheconEU08 {
-
- public static void main(String[] args) throws IOException {
- SlideShow ppt = new SlideShow();
- ppt.setPageSize(new Dimension(720, 540));
-
- slide1(ppt);
- slide2(ppt);
- slide3(ppt);
- slide4(ppt);
- slide5(ppt);
- slide6(ppt);
- slide7(ppt);
- slide8(ppt);
- slide9(ppt);
- slide10(ppt);
- slide11(ppt);
- slide12(ppt);
-
- FileOutputStream out = new FileOutputStream("apachecon_eu_08.ppt");
- ppt.write(out);
- out.close();
-
- }
-
- public static void slide1(SlideShow ppt) throws IOException {
- Slide slide = ppt.createSlide();
-
- TextBox box1 = new TextBox();
- TextRun tr1 = box1.getTextRun();
- tr1.setRunType(TextHeaderAtom.CENTER_TITLE_TYPE);
- tr1.setText("POI-HSLF");
- box1.setAnchor(new Rectangle(54, 78, 612, 115));
- slide.addShape(box1);
-
- TextBox box2 = new TextBox();
- TextRun tr2 = box2.getTextRun();
- tr2.setRunType(TextHeaderAtom.CENTRE_BODY_TYPE);
- tr2.setText("Java API To Access Microsoft PowerPoint Format Files");
- box2.setAnchor(new Rectangle(108, 204, 504, 138));
- slide.addShape(box2);
-
- TextBox box3 = new TextBox();
- TextRun tr3 = box3.getTextRun();
- tr3.getRichTextRuns()[0].setFontSize(32);
- box3.setHorizontalAlignment(TextBox.AlignCenter);
- tr3.setText(
- "Yegor Kozlov\r" +
- "yegor - apache - org");
- box3.setAnchor(new Rectangle(206, 348, 310, 84));
- slide.addShape(box3);
- }
-
- public static void slide2(SlideShow ppt) throws IOException {
- Slide slide = ppt.createSlide();
-
- TextBox box1 = new TextBox();
- TextRun tr1 = box1.getTextRun();
- tr1.setRunType(TextHeaderAtom.TITLE_TYPE);
- tr1.setText("What is HSLF?");
- box1.setAnchor(new Rectangle(36, 21, 648, 90));
- slide.addShape(box1);
-
- TextBox box2 = new TextBox();
- TextRun tr2 = box2.getTextRun();
- tr2.setRunType(TextHeaderAtom.BODY_TYPE);
- tr2.setText("HorribleSLideshowFormat is the POI Project's pure Java implementation " +
- "of the Powerpoint binary file format. \r" +
- "POI sub-project since 2005\r" +
- "Started by Nick Birch, Yegor Kozlov joined soon after");
- box2.setAnchor(new Rectangle(36, 126, 648, 356));
- slide.addShape(box2);
-
-
- }
-
- public static void slide3(SlideShow ppt) throws IOException {
- Slide slide = ppt.createSlide();
-
- TextBox box1 = new TextBox();
- TextRun tr1 = box1.getTextRun();
- tr1.setRunType(TextHeaderAtom.TITLE_TYPE);
- tr1.setText("HSLF in a Nutshell");
- box1.setAnchor(new Rectangle(36, 15, 648, 65));
- slide.addShape(box1);
-
- TextBox box2 = new TextBox();
- TextRun tr2 = box2.getTextRun();
- tr2.setRunType(TextHeaderAtom.BODY_TYPE);
- tr2.setText(
- "HSLF provides a way to read, create and modify MS PowerPoint presentations\r" +
- "Pure Java API - you don't need PowerPoint to read and write *.ppt files\r" +
- "Comprehensive support of PowerPoint objects");
- tr2.getRichTextRuns()[0].setFontSize(28);
- box2.setAnchor(new Rectangle(36, 80, 648, 200));
- slide.addShape(box2);
-
- TextBox box3 = new TextBox();
- TextRun tr3 = box3.getTextRun();
- tr3.setRunType(TextHeaderAtom.BODY_TYPE);
- tr3.setText(
- "Rich text\r" +
- "Tables\r" +
- "Shapes\r" +
- "Pictures\r" +
- "Master slides");
- tr3.getRichTextRuns()[0].setFontSize(24);
- tr3.getRichTextRuns()[0].setIndentLevel(1);
- box3.setAnchor(new Rectangle(36, 265, 648, 150));
- slide.addShape(box3);
-
- TextBox box4 = new TextBox();
- TextRun tr4 = box4.getTextRun();
- tr4.setRunType(TextHeaderAtom.BODY_TYPE);
- tr4.setText("Access to low level data structures");
- box4.setAnchor(new Rectangle(36, 430, 648, 50));
- slide.addShape(box4);
- }
-
- public static void slide4(SlideShow ppt) throws IOException {
- Slide slide = ppt.createSlide();
-
- String[][] txt1 = {
- {"Note"},
- {"This presentation was created programmatically using POI HSLF"}
- };
- Table table1 = new Table(2, 1);
- for (int i = 0; i < txt1.length; i++) {
- for (int j = 0; j < txt1[i].length; j++) {
- TableCell cell = table1.getCell(i, j);
- cell.setText(txt1[i][j]);
- cell.getTextRun().getRichTextRuns()[0].setFontSize(10);
- RichTextRun rt = cell.getTextRun().getRichTextRuns()[0];
- rt.setFontName("Arial");
- rt.setBold(true);
- if(i == 0){
- rt.setFontSize(32);
- rt.setFontColor(Color.white);
- cell.getFill().setForegroundColor(new Color(0, 153, 204));
- } else {
- rt.setFontSize(28);
- cell.getFill().setForegroundColor(new Color(235, 239, 241));
- }
- cell.setVerticalAlignment(TextBox.AnchorMiddle);
- }
- }
-
- Line border1 = table1.createBorder();
- border1.setLineColor(Color.black);
- border1.setLineWidth(1.0);
- table1.setAllBorders(border1);
-
- Line border2 = table1.createBorder();
- border2.setLineColor(Color.black);
- border2.setLineWidth(2.0);
- table1.setOutsideBorders(border2);
-
- table1.setColumnWidth(0, 510);
- table1.setRowHeight(0, 60);
- table1.setRowHeight(1, 100);
- slide.addShape(table1);
-
- table1.moveTo(100, 100);
-
- TextBox box1 = new TextBox();
- box1.setHorizontalAlignment(TextBox.AlignCenter);
- TextRun tr1 = box1.getTextRun();
- tr1.setText("The source code is available at\r" +
- "http://people.apache.org/~yegor/apachecon_eu08/");
- RichTextRun rt = tr1.getRichTextRuns()[0];
- rt.setFontSize(24);
- box1.setAnchor(new Rectangle(80, 356, 553, 65));
- slide.addShape(box1);
-
- }
-
- public static void slide5(SlideShow ppt) throws IOException {
- Slide slide = ppt.createSlide();
-
- TextBox box1 = new TextBox();
- TextRun tr1 = box1.getTextRun();
- tr1.setRunType(TextHeaderAtom.TITLE_TYPE);
- tr1.setText("HSLF in Action - 1\rData Extraction");
- box1.setAnchor(new Rectangle(36, 21, 648, 100));
- slide.addShape(box1);
-
- TextBox box2 = new TextBox();
- TextRun tr2 = box2.getTextRun();
- tr2.setRunType(TextHeaderAtom.BODY_TYPE);
- tr2.setText(
- "Text from slides and notes\r" +
- "Images\r" +
- "Shapes and their properties (type, position in the slide, color, font, etc.)");
- box2.setAnchor(new Rectangle(36, 150, 648, 300));
- slide.addShape(box2);
-
-
- }
-
- public static void slide6(SlideShow ppt) throws IOException {
- Slide slide = ppt.createSlide();
-
- TextBox box1 = new TextBox();
- TextRun tr1 = box1.getTextRun();
- tr1.setRunType(TextHeaderAtom.TITLE_TYPE);
- tr1.setText("HSLF in Action - 2");
- box1.setAnchor(new Rectangle(36, 20, 648, 90));
- slide.addShape(box1);
-
- TextBox box2 = new TextBox();
- TextRun tr2 = box2.getTextRun();
- tr2.getRichTextRuns()[0].setFontSize(18);
- tr2.setText("Creating a simple presentation from scratch");
- box2.setAnchor(new Rectangle(170, 100, 364, 30));
- slide.addShape(box2);
-
- TextBox box3 = new TextBox();
- TextRun tr3 = box3.getTextRun();
- RichTextRun rt3 = tr3.getRichTextRuns()[0];
- rt3.setFontName("Courier New");
- rt3.setFontSize(8);
- tr3.setText(
- " SlideShow ppt = new SlideShow();\r" +
- " Slide slide = ppt.createSlide();\r" +
- "\r" +
- " TextBox box2 = new TextBox();\r" +
- " box2.setHorizontalAlignment(TextBox.AlignCenter);\r" +
- " box2.setVerticalAlignment(TextBox.AnchorMiddle);\r" +
- " box2.getTextRun().setText(\"Java Code\");\r" +
- " box2.getFill().setForegroundColor(new Color(187, 224, 227));\r" +
- " box2.setLineColor(Color.black);\r" +
- " box2.setLineWidth(0.75);\r" +
- " box2.setAnchor(new Rectangle(66, 243, 170, 170));\r" +
- " slide.addShape(box2);\r" +
- "\r" +
- " TextBox box3 = new TextBox();\r" +
- " box3.setHorizontalAlignment(TextBox.AlignCenter);\r" +
- " box3.setVerticalAlignment(TextBox.AnchorMiddle);\r" +
- " box3.getTextRun().setText(\"*.ppt file\");\r" +
- " box3.setLineWidth(0.75);\r" +
- " box3.setLineColor(Color.black);\r" +
- " box3.getFill().setForegroundColor(new Color(187, 224, 227));\r" +
- " box3.setAnchor(new Rectangle(473, 243, 170, 170));\r" +
- " slide.addShape(box3);\r" +
- "\r" +
- " AutoShape box4 = new AutoShape(ShapeTypes.Arrow);\r" +
- " box4.getFill().setForegroundColor(new Color(187, 224, 227));\r" +
- " box4.setLineWidth(0.75);\r" +
- " box4.setLineColor(Color.black);\r" +
- " box4.setAnchor(new Rectangle(253, 288, 198, 85));\r" +
- " slide.addShape(box4);\r" +
- "\r" +
- " FileOutputStream out = new FileOutputStream(\"hslf-demo.ppt\");\r" +
- " ppt.write(out);\r" +
- " out.close();");
- box3.setAnchor(new Rectangle(30, 150, 618, 411));
- slide.addShape(box3);
- }
-
- public static void slide7(SlideShow ppt) throws IOException {
- Slide slide = ppt.createSlide();
-
- TextBox box2 = new TextBox();
- box2.setHorizontalAlignment(TextBox.AlignCenter);
- box2.setVerticalAlignment(TextBox.AnchorMiddle);
- box2.getTextRun().setText("Java Code");
- box2.getFill().setForegroundColor(new Color(187, 224, 227));
- box2.setLineColor(Color.black);
- box2.setLineWidth(0.75);
- box2.setAnchor(new Rectangle(66, 243, 170, 170));
- slide.addShape(box2);
-
- TextBox box3 = new TextBox();
- box3.setHorizontalAlignment(TextBox.AlignCenter);
- box3.setVerticalAlignment(TextBox.AnchorMiddle);
- box3.getTextRun().setText("*.ppt file");
- box3.setLineWidth(0.75);
- box3.setLineColor(Color.black);
- box3.getFill().setForegroundColor(new Color(187, 224, 227));
- box3.setAnchor(new Rectangle(473, 243, 170, 170));
- slide.addShape(box3);
-
- AutoShape box4 = new AutoShape(ShapeTypes.Arrow);
- box4.getFill().setForegroundColor(new Color(187, 224, 227));
- box4.setLineWidth(0.75);
- box4.setLineColor(Color.black);
- box4.setAnchor(new Rectangle(253, 288, 198, 85));
- slide.addShape(box4);
- }
-
- public static void slide8(SlideShow ppt) throws IOException {
- Slide slide = ppt.createSlide();
-
- TextBox box1 = new TextBox();
- TextRun tr1 = box1.getTextRun();
- tr1.setRunType(TextHeaderAtom.TITLE_TYPE);
- tr1.setText("Wait, there is more!");
- box1.setAnchor(new Rectangle(36, 21, 648, 90));
- slide.addShape(box1);
-
- TextBox box2 = new TextBox();
- TextRun tr2 = box2.getTextRun();
- tr2.setRunType(TextHeaderAtom.BODY_TYPE);
- tr2.setText(
- "Rich text\r" +
- "Tables\r" +
- "Pictures (JPEG, PNG, BMP, WMF, PICT)\r" +
- "Comprehensive formatting features");
- box2.setAnchor(new Rectangle(36, 126, 648, 356));
- slide.addShape(box2);
- }
-
- public static void slide9(SlideShow ppt) throws IOException {
- Slide slide = ppt.createSlide();
-
- TextBox box1 = new TextBox();
- TextRun tr1 = box1.getTextRun();
- tr1.setRunType(TextHeaderAtom.TITLE_TYPE);
- tr1.setText("HSLF in Action - 3");
- box1.setAnchor(new Rectangle(36, 20, 648, 50));
- slide.addShape(box1);
-
- TextBox box2 = new TextBox();
- TextRun tr2 = box2.getTextRun();
- tr2.getRichTextRuns()[0].setFontSize(18);
- tr2.setText("PPGraphics2D: PowerPoint Graphics2D driver");
- box2.setAnchor(new Rectangle(178, 70, 387, 30));
- slide.addShape(box2);
-
- TextBox box3 = new TextBox();
- TextRun tr3 = box3.getTextRun();
- RichTextRun rt3 = tr3.getRichTextRuns()[0];
- rt3.setFontName("Courier New");
- rt3.setFontSize(8);
- tr3.setText(
- " //bar chart data. The first value is the bar color, the second is the width\r" +
- " Object[] def = new Object[]{\r" +
- " Color.yellow, new Integer(100),\r" +
- " Color.green, new Integer(150),\r" +
- " Color.gray, new Integer(75),\r" +
- " Color.red, new Integer(200),\r" +
- " };\r" +
- "\r" +
- " SlideShow ppt = new SlideShow();\r" +
- " Slide slide = ppt.createSlide();\r" +
- "\r" +
- " ShapeGroup group = new ShapeGroup();\r" +
- " //define position of the drawing in the slide\r" +
- " Rectangle bounds = new java.awt.Rectangle(200, 100, 350, 300);\r" +
- " group.setAnchor(bounds);\r" +
- " slide.addShape(group);\r" +
- " Graphics2D graphics = new PPGraphics2D(group);\r" +
- "\r" +
- " //draw a simple bar graph\r" +
- " int x = bounds.x + 50, y = bounds.y + 50;\r" +
- " graphics.setFont(new Font(\"Arial\", Font.BOLD, 10));\r" +
- " for (int i = 0, idx = 1; i < def.length; i+=2, idx++) {\r" +
- " graphics.setColor(Color.black);\r" +
- " int width = ((Integer)def[i+1]).intValue();\r" +
- " graphics.drawString(\"Q\" + idx, x-20, y+20);\r" +
- " graphics.drawString(width + \"%\", x + width + 10, y + 20);\r" +
- " graphics.setColor((Color)def[i]);\r" +
- " graphics.fill(new Rectangle(x, y, width, 30));\r" +
- " y += 40;\r" +
- " }\r" +
- " graphics.setColor(Color.black);\r" +
- " graphics.setFont(new Font(\"Arial\", Font.BOLD, 14));\r" +
- " graphics.draw(bounds);\r" +
- " graphics.drawString(\"Performance\", x + 70, y + 40);\r" +
- "\r" +
- " FileOutputStream out = new FileOutputStream(\"hslf-demo.ppt\");\r" +
- " ppt.write(out);\r" +
- " out.close();");
- box3.setAnchor(new Rectangle(96, 110, 499, 378));
- slide.addShape(box3);
- }
-
- public static void slide10(SlideShow ppt) throws IOException {
- //bar chart data. The first value is the bar color, the second is the width
- Object[] def = new Object[]{
- Color.yellow, new Integer(100),
- Color.green, new Integer(150),
- Color.gray, new Integer(75),
- Color.red, new Integer(200),
- };
-
- Slide slide = ppt.createSlide();
-
- ShapeGroup group = new ShapeGroup();
- //define position of the drawing in the slide
- Rectangle bounds = new java.awt.Rectangle(200, 100, 350, 300);
- group.setAnchor(bounds);
- slide.addShape(group);
- Graphics2D graphics = new PPGraphics2D(group);
-
- //draw a simple bar graph
- int x = bounds.x + 50, y = bounds.y + 50;
- graphics.setFont(new Font("Arial", Font.BOLD, 10));
- for (int i = 0, idx = 1; i < def.length; i+=2, idx++) {
- graphics.setColor(Color.black);
- int width = ((Integer)def[i+1]).intValue();
- graphics.drawString("Q" + idx, x-20, y+20);
- graphics.drawString(width + "%", x + width + 10, y + 20);
- graphics.setColor((Color)def[i]);
- graphics.fill(new Rectangle(x, y, width, 30));
- y += 40;
- }
- graphics.setColor(Color.black);
- graphics.setFont(new Font("Arial", Font.BOLD, 14));
- graphics.draw(bounds);
- graphics.drawString("Performance", x + 70, y + 40);
-
- }
-
- public static void slide11(SlideShow ppt) throws IOException {
- Slide slide = ppt.createSlide();
-
- TextBox box1 = new TextBox();
- TextRun tr1 = box1.getTextRun();
- tr1.setRunType(TextHeaderAtom.TITLE_TYPE);
- tr1.setText("HSLF Development Plans");
- box1.setAnchor(new Rectangle(36, 21, 648, 90));
- slide.addShape(box1);
-
- TextBox box2 = new TextBox();
- TextRun tr2 = box2.getTextRun();
- tr2.setRunType(TextHeaderAtom.BODY_TYPE);
- tr2.getRichTextRuns()[0].setFontSize(32);
- tr2.setText(
- "Support for more PowerPoint functionality\r" +
- "Rendering slides into java.awt.Graphics2D");
- box2.setAnchor(new Rectangle(36, 126, 648, 100));
- slide.addShape(box2);
-
- TextBox box3 = new TextBox();
- TextRun tr3 = box3.getTextRun();
- tr3.setRunType(TextHeaderAtom.BODY_TYPE);
- tr3.getRichTextRuns()[0].setIndentLevel(1);
- tr3.setText(
- "A way to export slides into images or other formats");
- box3.setAnchor(new Rectangle(36, 220, 648, 70));
- slide.addShape(box3);
-
- TextBox box4 = new TextBox();
- TextRun tr4 = box4.getTextRun();
- tr4.setRunType(TextHeaderAtom.BODY_TYPE);
- tr4.getRichTextRuns()[0].setFontSize(32);
- tr4.setText(
- "Integration with Apache FOP - Formatting Objects Processor");
- box4.setAnchor(new Rectangle(36, 290, 648, 90));
- slide.addShape(box4);
-
- TextBox box5 = new TextBox();
- TextRun tr5 = box5.getTextRun();
- tr5.setRunType(TextHeaderAtom.BODY_TYPE);
- tr5.getRichTextRuns()[0].setIndentLevel(1);
- tr5.setText(
- "Transformation of XSL-FO into PPT\r" +
- "PPT2PDF transcoder");
- box5.setAnchor(new Rectangle(36, 380, 648, 100));
- slide.addShape(box5);
- }
-
- public static void slide12(SlideShow ppt) throws IOException {
- Slide slide = ppt.createSlide();
-
- TextBox box1 = new TextBox();
- TextRun tr1 = box1.getTextRun();
- tr1.setRunType(TextHeaderAtom.CENTER_TITLE_TYPE);
- tr1.setText("Questions?");
- box1.setAnchor(new Rectangle(54, 167, 612, 115));
- slide.addShape(box1);
-
- TextBox box2 = new TextBox();
- TextRun tr2 = box2.getTextRun();
- tr2.setRunType(TextHeaderAtom.CENTRE_BODY_TYPE);
- tr2.setText(
- "http://poi.apache.org/hslf/\r" +
- "http://people.apache.org/~yegor");
- box2.setAnchor(new Rectangle(108, 306, 504, 138));
- slide.addShape(box2);
- }
-}
+/* ====================================================================
+ 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.hslf.examples;
+
+import org.apache.poi.hslf.usermodel.*;
+import org.apache.poi.hslf.model.*;
+import org.apache.poi.hslf.record.TextHeaderAtom;
+
+import java.io.IOException;
+import java.io.FileOutputStream;
+import java.io.File;
+import java.awt.*;
+
+/**
+ * Presentation for Fast Feather Track on ApacheconEU 2008
+ *
+ * @author Yegor Kozlov
+ */
+public final class ApacheconEU08 {
+
+ public static void main(String[] args) throws IOException {
+ SlideShow ppt = new SlideShow();
+ ppt.setPageSize(new Dimension(720, 540));
+
+ slide1(ppt);
+ slide2(ppt);
+ slide3(ppt);
+ slide4(ppt);
+ slide5(ppt);
+ slide6(ppt);
+ slide7(ppt);
+ slide8(ppt);
+ slide9(ppt);
+ slide10(ppt);
+ slide11(ppt);
+ slide12(ppt);
+
+ FileOutputStream out = new FileOutputStream("apachecon_eu_08.ppt");
+ ppt.write(out);
+ out.close();
+
+ }
+
+ public static void slide1(SlideShow ppt) throws IOException {
+ Slide slide = ppt.createSlide();
+
+ TextBox box1 = new TextBox();
+ TextRun tr1 = box1.getTextRun();
+ tr1.setRunType(TextHeaderAtom.CENTER_TITLE_TYPE);
+ tr1.setText("POI-HSLF");
+ box1.setAnchor(new Rectangle(54, 78, 612, 115));
+ slide.addShape(box1);
+
+ TextBox box2 = new TextBox();
+ TextRun tr2 = box2.getTextRun();
+ tr2.setRunType(TextHeaderAtom.CENTRE_BODY_TYPE);
+ tr2.setText("Java API To Access Microsoft PowerPoint Format Files");
+ box2.setAnchor(new Rectangle(108, 204, 504, 138));
+ slide.addShape(box2);
+
+ TextBox box3 = new TextBox();
+ TextRun tr3 = box3.getTextRun();
+ tr3.getRichTextRuns()[0].setFontSize(32);
+ box3.setHorizontalAlignment(TextBox.AlignCenter);
+ tr3.setText(
+ "Yegor Kozlov\r" +
+ "yegor - apache - org");
+ box3.setAnchor(new Rectangle(206, 348, 310, 84));
+ slide.addShape(box3);
+ }
+
+ public static void slide2(SlideShow ppt) throws IOException {
+ Slide slide = ppt.createSlide();
+
+ TextBox box1 = new TextBox();
+ TextRun tr1 = box1.getTextRun();
+ tr1.setRunType(TextHeaderAtom.TITLE_TYPE);
+ tr1.setText("What is HSLF?");
+ box1.setAnchor(new Rectangle(36, 21, 648, 90));
+ slide.addShape(box1);
+
+ TextBox box2 = new TextBox();
+ TextRun tr2 = box2.getTextRun();
+ tr2.setRunType(TextHeaderAtom.BODY_TYPE);
+ tr2.setText("HorribleSLideshowFormat is the POI Project's pure Java implementation " +
+ "of the Powerpoint binary file format. \r" +
+ "POI sub-project since 2005\r" +
+ "Started by Nick Birch, Yegor Kozlov joined soon after");
+ box2.setAnchor(new Rectangle(36, 126, 648, 356));
+ slide.addShape(box2);
+
+
+ }
+
+ public static void slide3(SlideShow ppt) throws IOException {
+ Slide slide = ppt.createSlide();
+
+ TextBox box1 = new TextBox();
+ TextRun tr1 = box1.getTextRun();
+ tr1.setRunType(TextHeaderAtom.TITLE_TYPE);
+ tr1.setText("HSLF in a Nutshell");
+ box1.setAnchor(new Rectangle(36, 15, 648, 65));
+ slide.addShape(box1);
+
+ TextBox box2 = new TextBox();
+ TextRun tr2 = box2.getTextRun();
+ tr2.setRunType(TextHeaderAtom.BODY_TYPE);
+ tr2.setText(
+ "HSLF provides a way to read, create and modify MS PowerPoint presentations\r" +
+ "Pure Java API - you don't need PowerPoint to read and write *.ppt files\r" +
+ "Comprehensive support of PowerPoint objects");
+ tr2.getRichTextRuns()[0].setFontSize(28);
+ box2.setAnchor(new Rectangle(36, 80, 648, 200));
+ slide.addShape(box2);
+
+ TextBox box3 = new TextBox();
+ TextRun tr3 = box3.getTextRun();
+ tr3.setRunType(TextHeaderAtom.BODY_TYPE);
+ tr3.setText(
+ "Rich text\r" +
+ "Tables\r" +
+ "Shapes\r" +
+ "Pictures\r" +
+ "Master slides");
+ tr3.getRichTextRuns()[0].setFontSize(24);
+ tr3.getRichTextRuns()[0].setIndentLevel(1);
+ box3.setAnchor(new Rectangle(36, 265, 648, 150));
+ slide.addShape(box3);
+
+ TextBox box4 = new TextBox();
+ TextRun tr4 = box4.getTextRun();
+ tr4.setRunType(TextHeaderAtom.BODY_TYPE);
+ tr4.setText("Access to low level data structures");
+ box4.setAnchor(new Rectangle(36, 430, 648, 50));
+ slide.addShape(box4);
+ }
+
+ public static void slide4(SlideShow ppt) throws IOException {
+ Slide slide = ppt.createSlide();
+
+ String[][] txt1 = {
+ {"Note"},
+ {"This presentation was created programmatically using POI HSLF"}
+ };
+ Table table1 = new Table(2, 1);
+ for (int i = 0; i < txt1.length; i++) {
+ for (int j = 0; j < txt1[i].length; j++) {
+ TableCell cell = table1.getCell(i, j);
+ cell.setText(txt1[i][j]);
+ cell.getTextRun().getRichTextRuns()[0].setFontSize(10);
+ RichTextRun rt = cell.getTextRun().getRichTextRuns()[0];
+ rt.setFontName("Arial");
+ rt.setBold(true);
+ if(i == 0){
+ rt.setFontSize(32);
+ rt.setFontColor(Color.white);
+ cell.getFill().setForegroundColor(new Color(0, 153, 204));
+ } else {
+ rt.setFontSize(28);
+ cell.getFill().setForegroundColor(new Color(235, 239, 241));
+ }
+ cell.setVerticalAlignment(TextBox.AnchorMiddle);
+ }
+ }
+
+ Line border1 = table1.createBorder();
+ border1.setLineColor(Color.black);
+ border1.setLineWidth(1.0);
+ table1.setAllBorders(border1);
+
+ Line border2 = table1.createBorder();
+ border2.setLineColor(Color.black);
+ border2.setLineWidth(2.0);
+ table1.setOutsideBorders(border2);
+
+ table1.setColumnWidth(0, 510);
+ table1.setRowHeight(0, 60);
+ table1.setRowHeight(1, 100);
+ slide.addShape(table1);
+
+ table1.moveTo(100, 100);
+
+ TextBox box1 = new TextBox();
+ box1.setHorizontalAlignment(TextBox.AlignCenter);
+ TextRun tr1 = box1.getTextRun();
+ tr1.setText("The source code is available at\r" +
+ "http://people.apache.org/~yegor/apachecon_eu08/");
+ RichTextRun rt = tr1.getRichTextRuns()[0];
+ rt.setFontSize(24);
+ box1.setAnchor(new Rectangle(80, 356, 553, 65));
+ slide.addShape(box1);
+
+ }
+
+ public static void slide5(SlideShow ppt) throws IOException {
+ Slide slide = ppt.createSlide();
+
+ TextBox box1 = new TextBox();
+ TextRun tr1 = box1.getTextRun();
+ tr1.setRunType(TextHeaderAtom.TITLE_TYPE);
+ tr1.setText("HSLF in Action - 1\rData Extraction");
+ box1.setAnchor(new Rectangle(36, 21, 648, 100));
+ slide.addShape(box1);
+
+ TextBox box2 = new TextBox();
+ TextRun tr2 = box2.getTextRun();
+ tr2.setRunType(TextHeaderAtom.BODY_TYPE);
+ tr2.setText(
+ "Text from slides and notes\r" +
+ "Images\r" +
+ "Shapes and their properties (type, position in the slide, color, font, etc.)");
+ box2.setAnchor(new Rectangle(36, 150, 648, 300));
+ slide.addShape(box2);
+
+
+ }
+
+ public static void slide6(SlideShow ppt) throws IOException {
+ Slide slide = ppt.createSlide();
+
+ TextBox box1 = new TextBox();
+ TextRun tr1 = box1.getTextRun();
+ tr1.setRunType(TextHeaderAtom.TITLE_TYPE);
+ tr1.setText("HSLF in Action - 2");
+ box1.setAnchor(new Rectangle(36, 20, 648, 90));
+ slide.addShape(box1);
+
+ TextBox box2 = new TextBox();
+ TextRun tr2 = box2.getTextRun();
+ tr2.getRichTextRuns()[0].setFontSize(18);
+ tr2.setText("Creating a simple presentation from scratch");
+ box2.setAnchor(new Rectangle(170, 100, 364, 30));
+ slide.addShape(box2);
+
+ TextBox box3 = new TextBox();
+ TextRun tr3 = box3.getTextRun();
+ RichTextRun rt3 = tr3.getRichTextRuns()[0];
+ rt3.setFontName("Courier New");
+ rt3.setFontSize(8);
+ tr3.setText(
+ " SlideShow ppt = new SlideShow();\r" +
+ " Slide slide = ppt.createSlide();\r" +
+ "\r" +
+ " TextBox box2 = new TextBox();\r" +
+ " box2.setHorizontalAlignment(TextBox.AlignCenter);\r" +
+ " box2.setVerticalAlignment(TextBox.AnchorMiddle);\r" +
+ " box2.getTextRun().setText(\"Java Code\");\r" +
+ " box2.getFill().setForegroundColor(new Color(187, 224, 227));\r" +
+ " box2.setLineColor(Color.black);\r" +
+ " box2.setLineWidth(0.75);\r" +
+ " box2.setAnchor(new Rectangle(66, 243, 170, 170));\r" +
+ " slide.addShape(box2);\r" +
+ "\r" +
+ " TextBox box3 = new TextBox();\r" +
+ " box3.setHorizontalAlignment(TextBox.AlignCenter);\r" +
+ " box3.setVerticalAlignment(TextBox.AnchorMiddle);\r" +
+ " box3.getTextRun().setText(\"*.ppt file\");\r" +
+ " box3.setLineWidth(0.75);\r" +
+ " box3.setLineColor(Color.black);\r" +
+ " box3.getFill().setForegroundColor(new Color(187, 224, 227));\r" +
+ " box3.setAnchor(new Rectangle(473, 243, 170, 170));\r" +
+ " slide.addShape(box3);\r" +
+ "\r" +
+ " AutoShape box4 = new AutoShape(ShapeTypes.Arrow);\r" +
+ " box4.getFill().setForegroundColor(new Color(187, 224, 227));\r" +
+ " box4.setLineWidth(0.75);\r" +
+ " box4.setLineColor(Color.black);\r" +
+ " box4.setAnchor(new Rectangle(253, 288, 198, 85));\r" +
+ " slide.addShape(box4);\r" +
+ "\r" +
+ " FileOutputStream out = new FileOutputStream(\"hslf-demo.ppt\");\r" +
+ " ppt.write(out);\r" +
+ " out.close();");
+ box3.setAnchor(new Rectangle(30, 150, 618, 411));
+ slide.addShape(box3);
+ }
+
+ public static void slide7(SlideShow ppt) throws IOException {
+ Slide slide = ppt.createSlide();
+
+ TextBox box2 = new TextBox();
+ box2.setHorizontalAlignment(TextBox.AlignCenter);
+ box2.setVerticalAlignment(TextBox.AnchorMiddle);
+ box2.getTextRun().setText("Java Code");
+ box2.getFill().setForegroundColor(new Color(187, 224, 227));
+ box2.setLineColor(Color.black);
+ box2.setLineWidth(0.75);
+ box2.setAnchor(new Rectangle(66, 243, 170, 170));
+ slide.addShape(box2);
+
+ TextBox box3 = new TextBox();
+ box3.setHorizontalAlignment(TextBox.AlignCenter);
+ box3.setVerticalAlignment(TextBox.AnchorMiddle);
+ box3.getTextRun().setText("*.ppt file");
+ box3.setLineWidth(0.75);
+ box3.setLineColor(Color.black);
+ box3.getFill().setForegroundColor(new Color(187, 224, 227));
+ box3.setAnchor(new Rectangle(473, 243, 170, 170));
+ slide.addShape(box3);
+
+ AutoShape box4 = new AutoShape(ShapeTypes.Arrow);
+ box4.getFill().setForegroundColor(new Color(187, 224, 227));
+ box4.setLineWidth(0.75);
+ box4.setLineColor(Color.black);
+ box4.setAnchor(new Rectangle(253, 288, 198, 85));
+ slide.addShape(box4);
+ }
+
+ public static void slide8(SlideShow ppt) throws IOException {
+ Slide slide = ppt.createSlide();
+
+ TextBox box1 = new TextBox();
+ TextRun tr1 = box1.getTextRun();
+ tr1.setRunType(TextHeaderAtom.TITLE_TYPE);
+ tr1.setText("Wait, there is more!");
+ box1.setAnchor(new Rectangle(36, 21, 648, 90));
+ slide.addShape(box1);
+
+ TextBox box2 = new TextBox();
+ TextRun tr2 = box2.getTextRun();
+ tr2.setRunType(TextHeaderAtom.BODY_TYPE);
+ tr2.setText(
+ "Rich text\r" +
+ "Tables\r" +
+ "Pictures (JPEG, PNG, BMP, WMF, PICT)\r" +
+ "Comprehensive formatting features");
+ box2.setAnchor(new Rectangle(36, 126, 648, 356));
+ slide.addShape(box2);
+ }
+
+ public static void slide9(SlideShow ppt) throws IOException {
+ Slide slide = ppt.createSlide();
+
+ TextBox box1 = new TextBox();
+ TextRun tr1 = box1.getTextRun();
+ tr1.setRunType(TextHeaderAtom.TITLE_TYPE);
+ tr1.setText("HSLF in Action - 3");
+ box1.setAnchor(new Rectangle(36, 20, 648, 50));
+ slide.addShape(box1);
+
+ TextBox box2 = new TextBox();
+ TextRun tr2 = box2.getTextRun();
+ tr2.getRichTextRuns()[0].setFontSize(18);
+ tr2.setText("PPGraphics2D: PowerPoint Graphics2D driver");
+ box2.setAnchor(new Rectangle(178, 70, 387, 30));
+ slide.addShape(box2);
+
+ TextBox box3 = new TextBox();
+ TextRun tr3 = box3.getTextRun();
+ RichTextRun rt3 = tr3.getRichTextRuns()[0];
+ rt3.setFontName("Courier New");
+ rt3.setFontSize(8);
+ tr3.setText(
+ " //bar chart data. The first value is the bar color, the second is the width\r" +
+ " Object[] def = new Object[]{\r" +
+ " Color.yellow, new Integer(100),\r" +
+ " Color.green, new Integer(150),\r" +
+ " Color.gray, new Integer(75),\r" +
+ " Color.red, new Integer(200),\r" +
+ " };\r" +
+ "\r" +
+ " SlideShow ppt = new SlideShow();\r" +
+ " Slide slide = ppt.createSlide();\r" +
+ "\r" +
+ " ShapeGroup group = new ShapeGroup();\r" +
+ " //define position of the drawing in the slide\r" +
+ " Rectangle bounds = new java.awt.Rectangle(200, 100, 350, 300);\r" +
+ " group.setAnchor(bounds);\r" +
+ " slide.addShape(group);\r" +
+ " Graphics2D graphics = new PPGraphics2D(group);\r" +
+ "\r" +
+ " //draw a simple bar graph\r" +
+ " int x = bounds.x + 50, y = bounds.y + 50;\r" +
+ " graphics.setFont(new Font(\"Arial\", Font.BOLD, 10));\r" +
+ " for (int i = 0, idx = 1; i < def.length; i+=2, idx++) {\r" +
+ " graphics.setColor(Color.black);\r" +
+ " int width = ((Integer)def[i+1]).intValue();\r" +
+ " graphics.drawString(\"Q\" + idx, x-20, y+20);\r" +
+ " graphics.drawString(width + \"%\", x + width + 10, y + 20);\r" +
+ " graphics.setColor((Color)def[i]);\r" +
+ " graphics.fill(new Rectangle(x, y, width, 30));\r" +
+ " y += 40;\r" +
+ " }\r" +
+ " graphics.setColor(Color.black);\r" +
+ " graphics.setFont(new Font(\"Arial\", Font.BOLD, 14));\r" +
+ " graphics.draw(bounds);\r" +
+ " graphics.drawString(\"Performance\", x + 70, y + 40);\r" +
+ "\r" +
+ " FileOutputStream out = new FileOutputStream(\"hslf-demo.ppt\");\r" +
+ " ppt.write(out);\r" +
+ " out.close();");
+ box3.setAnchor(new Rectangle(96, 110, 499, 378));
+ slide.addShape(box3);
+ }
+
+ public static void slide10(SlideShow ppt) throws IOException {
+ //bar chart data. The first value is the bar color, the second is the width
+ Object[] def = new Object[]{
+ Color.yellow, new Integer(100),
+ Color.green, new Integer(150),
+ Color.gray, new Integer(75),
+ Color.red, new Integer(200),
+ };
+
+ Slide slide = ppt.createSlide();
+
+ ShapeGroup group = new ShapeGroup();
+ //define position of the drawing in the slide
+ Rectangle bounds = new java.awt.Rectangle(200, 100, 350, 300);
+ group.setAnchor(bounds);
+ slide.addShape(group);
+ Graphics2D graphics = new PPGraphics2D(group);
+
+ //draw a simple bar graph
+ int x = bounds.x + 50, y = bounds.y + 50;
+ graphics.setFont(new Font("Arial", Font.BOLD, 10));
+ for (int i = 0, idx = 1; i < def.length; i+=2, idx++) {
+ graphics.setColor(Color.black);
+ int width = ((Integer)def[i+1]).intValue();
+ graphics.drawString("Q" + idx, x-20, y+20);
+ graphics.drawString(width + "%", x + width + 10, y + 20);
+ graphics.setColor((Color)def[i]);
+ graphics.fill(new Rectangle(x, y, width, 30));
+ y += 40;
+ }
+ graphics.setColor(Color.black);
+ graphics.setFont(new Font("Arial", Font.BOLD, 14));
+ graphics.draw(bounds);
+ graphics.drawString("Performance", x + 70, y + 40);
+
+ }
+
+ public static void slide11(SlideShow ppt) throws IOException {
+ Slide slide = ppt.createSlide();
+
+ TextBox box1 = new TextBox();
+ TextRun tr1 = box1.getTextRun();
+ tr1.setRunType(TextHeaderAtom.TITLE_TYPE);
+ tr1.setText("HSLF Development Plans");
+ box1.setAnchor(new Rectangle(36, 21, 648, 90));
+ slide.addShape(box1);
+
+ TextBox box2 = new TextBox();
+ TextRun tr2 = box2.getTextRun();
+ tr2.setRunType(TextHeaderAtom.BODY_TYPE);
+ tr2.getRichTextRuns()[0].setFontSize(32);
+ tr2.setText(
+ "Support for more PowerPoint functionality\r" +
+ "Rendering slides into java.awt.Graphics2D");
+ box2.setAnchor(new Rectangle(36, 126, 648, 100));
+ slide.addShape(box2);
+
+ TextBox box3 = new TextBox();
+ TextRun tr3 = box3.getTextRun();
+ tr3.setRunType(TextHeaderAtom.BODY_TYPE);
+ tr3.getRichTextRuns()[0].setIndentLevel(1);
+ tr3.setText(
+ "A way to export slides into images or other formats");
+ box3.setAnchor(new Rectangle(36, 220, 648, 70));
+ slide.addShape(box3);
+
+ TextBox box4 = new TextBox();
+ TextRun tr4 = box4.getTextRun();
+ tr4.setRunType(TextHeaderAtom.BODY_TYPE);
+ tr4.getRichTextRuns()[0].setFontSize(32);
+ tr4.setText(
+ "Integration with Apache FOP - Formatting Objects Processor");
+ box4.setAnchor(new Rectangle(36, 290, 648, 90));
+ slide.addShape(box4);
+
+ TextBox box5 = new TextBox();
+ TextRun tr5 = box5.getTextRun();
+ tr5.setRunType(TextHeaderAtom.BODY_TYPE);
+ tr5.getRichTextRuns()[0].setIndentLevel(1);
+ tr5.setText(
+ "Transformation of XSL-FO into PPT\r" +
+ "PPT2PDF transcoder");
+ box5.setAnchor(new Rectangle(36, 380, 648, 100));
+ slide.addShape(box5);
+ }
+
+ public static void slide12(SlideShow ppt) throws IOException {
+ Slide slide = ppt.createSlide();
+
+ TextBox box1 = new TextBox();
+ TextRun tr1 = box1.getTextRun();
+ tr1.setRunType(TextHeaderAtom.CENTER_TITLE_TYPE);
+ tr1.setText("Questions?");
+ box1.setAnchor(new Rectangle(54, 167, 612, 115));
+ slide.addShape(box1);
+
+ TextBox box2 = new TextBox();
+ TextRun tr2 = box2.getTextRun();
+ tr2.setRunType(TextHeaderAtom.CENTRE_BODY_TYPE);
+ tr2.setText(
+ "http://poi.apache.org/hslf/\r" +
+ "http://people.apache.org/~yegor");
+ box2.setAnchor(new Rectangle(108, 306, 504, 138));
+ slide.addShape(box2);
+ }
+}
diff --git a/src/scratchpad/examples/src/org/apache/poi/hslf/examples/BulletsDemo.java b/src/scratchpad/examples/src/org/apache/poi/hslf/examples/BulletsDemo.java
index a4559713c4..3a97b61aa0 100644
--- a/src/scratchpad/examples/src/org/apache/poi/hslf/examples/BulletsDemo.java
+++ b/src/scratchpad/examples/src/org/apache/poi/hslf/examples/BulletsDemo.java
@@ -1,62 +1,62 @@
-
-/* ====================================================================
- 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.hslf.examples;
-
-import org.apache.poi.hslf.usermodel.SlideShow;
-import org.apache.poi.hslf.usermodel.RichTextRun;
-import org.apache.poi.hslf.model.Slide;
-import org.apache.poi.hslf.model.TextBox;
-
-import java.io.FileOutputStream;
-
-/**
- * How to create a single-level bulleted list
- * and change some of the bullet attributes
- *
- * @author Yegor Kozlov
- */
-public class BulletsDemo {
-
- public static void main(String[] args) throws Exception {
-
- SlideShow ppt = new SlideShow();
-
- Slide slide = ppt.createSlide();
-
- TextBox shape = new TextBox();
- RichTextRun rt = shape.getTextRun().getRichTextRuns()[0];
- shape.setText(
- "January\r" +
- "February\r" +
- "March\r" +
- "April");
- rt.setFontSize(42);
- rt.setBullet(true);
- rt.setBulletOffset(0); //bullet offset
- rt.setTextOffset(50); //text offset (should be greater than bullet offset)
- rt.setBulletChar('\u263A'); //bullet character
- slide.addShape(shape);
-
- shape.setAnchor(new java.awt.Rectangle(50, 50, 500, 300)); //position of the text box in the slide
- slide.addShape(shape);
-
- FileOutputStream out = new FileOutputStream("bullets.ppt");
- ppt.write(out);
- out.close();
- }
-}
+/* ====================================================================
+ 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.hslf.examples;
+
+import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.usermodel.RichTextRun;
+import org.apache.poi.hslf.model.Slide;
+import org.apache.poi.hslf.model.TextBox;
+
+import java.io.FileOutputStream;
+
+/**
+ * How to create a single-level bulleted list
+ * and change some of the bullet attributes
+ *
+ * @author Yegor Kozlov
+ */
+public final class BulletsDemo {
+
+ public static void main(String[] args) throws Exception {
+
+ SlideShow ppt = new SlideShow();
+
+ Slide slide = ppt.createSlide();
+
+ TextBox shape = new TextBox();
+ RichTextRun rt = shape.getTextRun().getRichTextRuns()[0];
+ shape.setText(
+ "January\r" +
+ "February\r" +
+ "March\r" +
+ "April");
+ rt.setFontSize(42);
+ rt.setBullet(true);
+ rt.setBulletOffset(0); //bullet offset
+ rt.setTextOffset(50); //text offset (should be greater than bullet offset)
+ rt.setBulletChar('\u263A'); //bullet character
+ slide.addShape(shape);
+
+ shape.setAnchor(new java.awt.Rectangle(50, 50, 500, 300)); //position of the text box in the slide
+ slide.addShape(shape);
+
+ FileOutputStream out = new FileOutputStream("bullets.ppt");
+ ppt.write(out);
+ out.close();
+ }
+}
diff --git a/src/scratchpad/examples/src/org/apache/poi/hslf/examples/CreateHyperlink.java b/src/scratchpad/examples/src/org/apache/poi/hslf/examples/CreateHyperlink.java
index 9254c37da3..c20a2f186f 100755
--- a/src/scratchpad/examples/src/org/apache/poi/hslf/examples/CreateHyperlink.java
+++ b/src/scratchpad/examples/src/org/apache/poi/hslf/examples/CreateHyperlink.java
@@ -1,59 +1,60 @@
-/* ====================================================================
- 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.hslf.examples;
-
-import org.apache.poi.hslf.usermodel.SlideShow;
-import org.apache.poi.hslf.usermodel.RichTextRun;
-import org.apache.poi.hslf.model.*;
-
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.awt.*;
-
-/**
- * Demonstrates how to create hyperlinks in PowerPoint presentations
- *
- * @author Yegor Kozlov
- */
-public class CreateHyperlink {
-
- public static void main(String[] args) throws Exception {
- SlideShow ppt = new SlideShow();
-
- Slide slide = ppt.createSlide();
-
- TextBox shape = new TextBox();
- shape.setText("Apache POI");
- Rectangle anchor = new Rectangle(100, 100, 200, 50);
- shape.setAnchor(anchor);
-
- String text = shape.getText();
- Hyperlink link = new Hyperlink();
- link.setAddress("http://www.apache.org");
- link.setTitle(shape.getText());
- int linkId = ppt.addHyperlink(link);
-
- shape.setHyperlink(linkId, 0, text.length());
-
- slide.addShape(shape);
-
- FileOutputStream out = new FileOutputStream("hyperlink.ppt");
- ppt.write(out);
- out.close();
-
- }
-}
+/* ====================================================================
+ 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.hslf.examples;
+
+import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.usermodel.RichTextRun;
+import org.apache.poi.hslf.model.*;
+
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.awt.*;
+
+/**
+ * Demonstrates how to create hyperlinks in PowerPoint presentations
+ *
+ * @author Yegor Kozlov
+ */
+public final class CreateHyperlink {
+
+ public static void main(String[] args) throws Exception {
+ SlideShow ppt = new SlideShow();
+
+ Slide slide = ppt.createSlide();
+
+ TextBox shape = new TextBox();
+ shape.setText("Apache POI");
+ Rectangle anchor = new Rectangle(100, 100, 200, 50);
+ shape.setAnchor(anchor);
+
+ String text = shape.getText();
+ Hyperlink link = new Hyperlink();
+ link.setAddress("http://www.apache.org");
+ link.setTitle(shape.getText());
+ int linkId = ppt.addHyperlink(link);
+
+ shape.setHyperlink(linkId, 0, text.length());
+
+ slide.addShape(shape);
+
+ FileOutputStream out = new FileOutputStream("hyperlink.ppt");
+ ppt.write(out);
+ out.close();
+
+ }
+}
diff --git a/src/scratchpad/examples/src/org/apache/poi/hslf/examples/DataExtraction.java b/src/scratchpad/examples/src/org/apache/poi/hslf/examples/DataExtraction.java
index 611466c924..a278e894b6 100755
--- a/src/scratchpad/examples/src/org/apache/poi/hslf/examples/DataExtraction.java
+++ b/src/scratchpad/examples/src/org/apache/poi/hslf/examples/DataExtraction.java
@@ -1,149 +1,148 @@
-
-/* ====================================================================
- 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.hslf.examples;
-
-import org.apache.poi.hslf.usermodel.*;
-import org.apache.poi.hslf.model.*;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.hwpf.HWPFDocument;
-import org.apache.poi.hwpf.usermodel.Range;
-import org.apache.poi.hwpf.usermodel.Paragraph;
-
-import java.io.*;
-
-/**
- * Demonstrates how you can extract misc embedded data from a ppt file
- *
- * @author Yegor Kozlov
- */
-public class DataExtraction {
-
- public static void main(String args[]) throws Exception {
-
- if (args.length == 0) {
- usage();
- return;
- }
-
- FileInputStream is = new FileInputStream(args[0]);
- SlideShow ppt = new SlideShow(is);
- is.close();
-
- //extract all sound files embedded in this presentation
- SoundData[] sound = ppt.getSoundData();
- for (int i = 0; i < sound.length; i++) {
- String type = sound[i].getSoundType(); //*.wav
- String name = sound[i].getSoundName(); //typically file name
- byte[] data = sound[i].getData(); //raw bytes
-
- //save the sound on disk
- FileOutputStream out = new FileOutputStream(name + type);
- out.write(data);
- out.close();
- }
-
- //extract embedded OLE documents
- Slide[] slide = ppt.getSlides();
- for (int i = 0; i < slide.length; i++) {
- Shape[] shape = slide[i].getShapes();
- for (int j = 0; j < shape.length; j++) {
- if (shape[j] instanceof OLEShape) {
- OLEShape ole = (OLEShape) shape[j];
- ObjectData data = ole.getObjectData();
- String name = ole.getInstanceName();
- if ("Worksheet".equals(name)) {
-
- //read xls
- HSSFWorkbook wb = new HSSFWorkbook(data.getData());
-
- } else if ("Document".equals(name)) {
- HWPFDocument doc = new HWPFDocument(data.getData());
- //read the word document
- Range r = doc.getRange();
- for(int k = 0; k < r.numParagraphs(); k++) {
- Paragraph p = r.getParagraph(k);
- System.out.println(p.text());
- }
-
- //save on disk
- FileOutputStream out = new FileOutputStream(name + "-("+(j)+").doc");
- doc.write(out);
- out.close();
- } else {
- FileOutputStream out = new FileOutputStream(ole.getProgID() + "-"+(j+1)+".dat");
- InputStream dis = data.getData();
- byte[] chunk = new byte[2048];
- int count;
- while ((count = dis.read(chunk)) >= 0) {
- out.write(chunk,0,count);
- }
- is.close();
- out.close();
- }
- }
-
- }
- }
-
- //Pictures
- for (int i = 0; i < slide.length; i++) {
- Shape[] shape = slide[i].getShapes();
- for (int j = 0; j < shape.length; j++) {
- if (shape[j] instanceof Picture) {
- Picture p = (Picture) shape[j];
- PictureData data = p.getPictureData();
- String name = p.getPictureName();
- int type = data.getType();
- String ext;
- switch (type) {
- case Picture.JPEG:
- ext = ".jpg";
- break;
- case Picture.PNG:
- ext = ".png";
- break;
- case Picture.WMF:
- ext = ".wmf";
- break;
- case Picture.EMF:
- ext = ".emf";
- break;
- case Picture.PICT:
- ext = ".pict";
- break;
- case Picture.DIB:
- ext = ".dib";
- break;
- default:
- continue;
- }
- FileOutputStream out = new FileOutputStream("pict-" + j + ext);
- out.write(data.getData());
- out.close();
- }
-
- }
- }
-
- }
-
- private static void usage(){
- System.out.println("Usage: DataExtraction ppt");
- }
-}
+/* ====================================================================
+ 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.hslf.examples;
+
+import org.apache.poi.hslf.usermodel.*;
+import org.apache.poi.hslf.model.*;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.hwpf.HWPFDocument;
+import org.apache.poi.hwpf.usermodel.Range;
+import org.apache.poi.hwpf.usermodel.Paragraph;
+
+import java.io.*;
+
+/**
+ * Demonstrates how you can extract misc embedded data from a ppt file
+ *
+ * @author Yegor Kozlov
+ */
+public final class DataExtraction {
+
+ public static void main(String args[]) throws Exception {
+
+ if (args.length == 0) {
+ usage();
+ return;
+ }
+
+ FileInputStream is = new FileInputStream(args[0]);
+ SlideShow ppt = new SlideShow(is);
+ is.close();
+
+ //extract all sound files embedded in this presentation
+ SoundData[] sound = ppt.getSoundData();
+ for (int i = 0; i < sound.length; i++) {
+ String type = sound[i].getSoundType(); //*.wav
+ String name = sound[i].getSoundName(); //typically file name
+ byte[] data = sound[i].getData(); //raw bytes
+
+ //save the sound on disk
+ FileOutputStream out = new FileOutputStream(name + type);
+ out.write(data);
+ out.close();
+ }
+
+ //extract embedded OLE documents
+ Slide[] slide = ppt.getSlides();
+ for (int i = 0; i < slide.length; i++) {
+ Shape[] shape = slide[i].getShapes();
+ for (int j = 0; j < shape.length; j++) {
+ if (shape[j] instanceof OLEShape) {
+ OLEShape ole = (OLEShape) shape[j];
+ ObjectData data = ole.getObjectData();
+ String name = ole.getInstanceName();
+ if ("Worksheet".equals(name)) {
+
+ //read xls
+ HSSFWorkbook wb = new HSSFWorkbook(data.getData());
+
+ } else if ("Document".equals(name)) {
+ HWPFDocument doc = new HWPFDocument(data.getData());
+ //read the word document
+ Range r = doc.getRange();
+ for(int k = 0; k < r.numParagraphs(); k++) {
+ Paragraph p = r.getParagraph(k);
+ System.out.println(p.text());
+ }
+
+ //save on disk
+ FileOutputStream out = new FileOutputStream(name + "-("+(j)+").doc");
+ doc.write(out);
+ out.close();
+ } else {
+ FileOutputStream out = new FileOutputStream(ole.getProgID() + "-"+(j+1)+".dat");
+ InputStream dis = data.getData();
+ byte[] chunk = new byte[2048];
+ int count;
+ while ((count = dis.read(chunk)) >= 0) {
+ out.write(chunk,0,count);
+ }
+ is.close();
+ out.close();
+ }
+ }
+
+ }
+ }
+
+ //Pictures
+ for (int i = 0; i < slide.length; i++) {
+ Shape[] shape = slide[i].getShapes();
+ for (int j = 0; j < shape.length; j++) {
+ if (shape[j] instanceof Picture) {
+ Picture p = (Picture) shape[j];
+ PictureData data = p.getPictureData();
+ String name = p.getPictureName();
+ int type = data.getType();
+ String ext;
+ switch (type) {
+ case Picture.JPEG:
+ ext = ".jpg";
+ break;
+ case Picture.PNG:
+ ext = ".png";
+ break;
+ case Picture.WMF:
+ ext = ".wmf";
+ break;
+ case Picture.EMF:
+ ext = ".emf";
+ break;
+ case Picture.PICT:
+ ext = ".pict";
+ break;
+ case Picture.DIB:
+ ext = ".dib";
+ break;
+ default:
+ continue;
+ }
+ FileOutputStream out = new FileOutputStream("pict-" + j + ext);
+ out.write(data.getData());
+ out.close();
+ }
+
+ }
+ }
+
+ }
+
+ private static void usage(){
+ System.out.println("Usage: DataExtraction ppt");
+ }
+}
diff --git a/src/scratchpad/examples/src/org/apache/poi/hslf/examples/Graphics2DDemo.java b/src/scratchpad/examples/src/org/apache/poi/hslf/examples/Graphics2DDemo.java
index 87a59c38bb..b3d85640e0 100755
--- a/src/scratchpad/examples/src/org/apache/poi/hslf/examples/Graphics2DDemo.java
+++ b/src/scratchpad/examples/src/org/apache/poi/hslf/examples/Graphics2DDemo.java
@@ -1,80 +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.hslf.examples;
-
-import org.apache.poi.hslf.usermodel.SlideShow;
-import org.apache.poi.hslf.model.*;
-
-import java.awt.*;
-import java.io.FileOutputStream;
-import java.io.FileInputStream;
-
-/**
- * Demonstrates how to draw into a slide using the HSLF Graphics2D driver.
- *
- * @author Yegor Kozlov
- */
-public class Graphics2DDemo {
-
- /**
- * A simple bar chart demo
- */
- public static void main(String[] args) throws Exception {
- SlideShow ppt = new SlideShow();
-
- //bar chart data. The first value is the bar color, the second is the width
- Object[] def = new Object[]{
- Color.yellow, new Integer(40),
- Color.green, new Integer(60),
- Color.gray, new Integer(30),
- Color.red, new Integer(80),
- };
-
- Slide slide = ppt.createSlide();
-
- ShapeGroup group = new ShapeGroup();
- //define position of the drawing in the slide
- Rectangle bounds = new java.awt.Rectangle(200, 100, 350, 300);
- group.setAnchor(bounds);
- group.setCoordinates(new java.awt.Rectangle(0, 0, 100, 100));
- slide.addShape(group);
- Graphics2D graphics = new PPGraphics2D(group);
-
- //draw a simple bar graph
- int x = 10, y = 10;
- graphics.setFont(new Font("Arial", Font.BOLD, 10));
- for (int i = 0, idx = 1; i < def.length; i+=2, idx++) {
- graphics.setColor(Color.black);
- int width = ((Integer)def[i+1]).intValue();
- graphics.drawString("Q" + idx, x-5, y+10);
- graphics.drawString(width + "%", x + width+3, y + 10);
- graphics.setColor((Color)def[i]);
- graphics.fill(new Rectangle(x, y, width, 10));
- y += 15;
- }
- graphics.setColor(Color.black);
- graphics.setFont(new Font("Arial", Font.BOLD, 14));
- graphics.draw(group.getCoordinates());
- graphics.drawString("Performance", x + 30, y + 10);
-
- FileOutputStream out = new FileOutputStream("hslf-graphics.ppt");
- ppt.write(out);
- out.close();
- }
-
-}
+/* ====================================================================
+ 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.hslf.examples;
+
+import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.model.*;
+
+import java.awt.*;
+import java.io.FileOutputStream;
+import java.io.FileInputStream;
+
+/**
+ * Demonstrates how to draw into a slide using the HSLF Graphics2D driver.
+ *
+ * @author Yegor Kozlov
+ */
+public final class Graphics2DDemo {
+
+ /**
+ * A simple bar chart demo
+ */
+ public static void main(String[] args) throws Exception {
+ SlideShow ppt = new SlideShow();
+
+ //bar chart data. The first value is the bar color, the second is the width
+ Object[] def = new Object[]{
+ Color.yellow, new Integer(40),
+ Color.green, new Integer(60),
+ Color.gray, new Integer(30),
+ Color.red, new Integer(80),
+ };
+
+ Slide slide = ppt.createSlide();
+
+ ShapeGroup group = new ShapeGroup();
+ //define position of the drawing in the slide
+ Rectangle bounds = new java.awt.Rectangle(200, 100, 350, 300);
+ group.setAnchor(bounds);
+ group.setCoordinates(new java.awt.Rectangle(0, 0, 100, 100));
+ slide.addShape(group);
+ Graphics2D graphics = new PPGraphics2D(group);
+
+ //draw a simple bar graph
+ int x = 10, y = 10;
+ graphics.setFont(new Font("Arial", Font.BOLD, 10));
+ for (int i = 0, idx = 1; i < def.length; i+=2, idx++) {
+ graphics.setColor(Color.black);
+ int width = ((Integer)def[i+1]).intValue();
+ graphics.drawString("Q" + idx, x-5, y+10);
+ graphics.drawString(width + "%", x + width+3, y + 10);
+ graphics.setColor((Color)def[i]);
+ graphics.fill(new Rectangle(x, y, width, 10));
+ y += 15;
+ }
+ graphics.setColor(Color.black);
+ graphics.setFont(new Font("Arial", Font.BOLD, 14));
+ graphics.draw(group.getCoordinates());
+ graphics.drawString("Performance", x + 30, y + 10);
+
+ FileOutputStream out = new FileOutputStream("hslf-graphics.ppt");
+ ppt.write(out);
+ out.close();
+ }
+
+}
diff --git a/src/scratchpad/examples/src/org/apache/poi/hslf/examples/Hyperlinks.java b/src/scratchpad/examples/src/org/apache/poi/hslf/examples/Hyperlinks.java
index f919e545ff..968426c513 100644
--- a/src/scratchpad/examples/src/org/apache/poi/hslf/examples/Hyperlinks.java
+++ b/src/scratchpad/examples/src/org/apache/poi/hslf/examples/Hyperlinks.java
@@ -1,80 +1,81 @@
-/* ====================================================================
- 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.hslf.examples;
-
-import org.apache.poi.hslf.usermodel.SlideShow;
-import org.apache.poi.hslf.model.Slide;
-import org.apache.poi.hslf.model.TextRun;
-import org.apache.poi.hslf.model.Hyperlink;
-import org.apache.poi.hslf.model.Shape;
-
-import java.io.FileInputStream;
-
-/**
- * Demonstrates how to read hyperlinks from a presentation
- *
- * @author Yegor Kozlov
- */
-public class Hyperlinks {
-
- public static void main(String[] args) throws Exception {
- for (int i = 0; i < args.length; i++) {
- FileInputStream is = new FileInputStream(args[i]);
- SlideShow ppt = new SlideShow(is);
- is.close();
-
- Slide[] slide = ppt.getSlides();
- for (int j = 0; j < slide.length; j++) {
- System.out.println("slide " + slide[j].getSlideNumber());
-
- //read hyperlinks from the slide's text runs
- System.out.println("reading hyperlinks from the text runs");
- TextRun[] txt = slide[j].getTextRuns();
- for (int k = 0; k < txt.length; k++) {
- String text = txt[k].getText();
- Hyperlink[] links = txt[k].getHyperlinks();
- if(links != null) for (int l = 0; l < links.length; l++) {
- Hyperlink link = links[l];
- String title = link.getTitle();
- String address = link.getAddress();
- System.out.println(" " + title);
- System.out.println(" " + address);
- String substring = text.substring(link.getStartIndex(), link.getEndIndex()-1);//in ppt end index is inclusive
- System.out.println(" " + substring);
- }
- }
-
- //in PowerPoint you can assign a hyperlink to a shape without text,
- //for example to a Line object. The code below demonstrates how to
- //read such hyperlinks
- System.out.println(" reading hyperlinks from the slide's shapes");
- Shape[] sh = slide[j].getShapes();
- for (int k = 0; k < sh.length; k++) {
- Hyperlink link = sh[k].getHyperlink();
- if(link != null) {
- String title = link.getTitle();
- String address = link.getAddress();
- System.out.println(" " + title);
- System.out.println(" " + address);
- }
- }
- }
-
- }
-
- }
-}
+/* ====================================================================
+ 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.hslf.examples;
+
+import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.model.Slide;
+import org.apache.poi.hslf.model.TextRun;
+import org.apache.poi.hslf.model.Hyperlink;
+import org.apache.poi.hslf.model.Shape;
+
+import java.io.FileInputStream;
+
+/**
+ * Demonstrates how to read hyperlinks from a presentation
+ *
+ * @author Yegor Kozlov
+ */
+public final class Hyperlinks {
+
+ public static void main(String[] args) throws Exception {
+ for (int i = 0; i < args.length; i++) {
+ FileInputStream is = new FileInputStream(args[i]);
+ SlideShow ppt = new SlideShow(is);
+ is.close();
+
+ Slide[] slide = ppt.getSlides();
+ for (int j = 0; j < slide.length; j++) {
+ System.out.println("slide " + slide[j].getSlideNumber());
+
+ //read hyperlinks from the slide's text runs
+ System.out.println("reading hyperlinks from the text runs");
+ TextRun[] txt = slide[j].getTextRuns();
+ for (int k = 0; k < txt.length; k++) {
+ String text = txt[k].getText();
+ Hyperlink[] links = txt[k].getHyperlinks();
+ if(links != null) for (int l = 0; l < links.length; l++) {
+ Hyperlink link = links[l];
+ String title = link.getTitle();
+ String address = link.getAddress();
+ System.out.println(" " + title);
+ System.out.println(" " + address);
+ String substring = text.substring(link.getStartIndex(), link.getEndIndex()-1);//in ppt end index is inclusive
+ System.out.println(" " + substring);
+ }
+ }
+
+ //in PowerPoint you can assign a hyperlink to a shape without text,
+ //for example to a Line object. The code below demonstrates how to
+ //read such hyperlinks
+ System.out.println(" reading hyperlinks from the slide's shapes");
+ Shape[] sh = slide[j].getShapes();
+ for (int k = 0; k < sh.length; k++) {
+ Hyperlink link = sh[k].getHyperlink();
+ if(link != null) {
+ String title = link.getTitle();
+ String address = link.getAddress();
+ System.out.println(" " + title);
+ System.out.println(" " + address);
+ }
+ }
+ }
+
+ }
+
+ }
+}
diff --git a/src/scratchpad/examples/src/org/apache/poi/hslf/examples/PPT2PNG.java b/src/scratchpad/examples/src/org/apache/poi/hslf/examples/PPT2PNG.java
index 8a75297121..2371f0fbf6 100755
--- a/src/scratchpad/examples/src/org/apache/poi/hslf/examples/PPT2PNG.java
+++ b/src/scratchpad/examples/src/org/apache/poi/hslf/examples/PPT2PNG.java
@@ -1,108 +1,107 @@
-
-/* ====================================================================
- 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.hslf.examples;
-
-import org.apache.poi.hslf.usermodel.*;
-import org.apache.poi.hslf.model.*;
-import org.apache.poi.hslf.record.TextHeaderAtom;
-
-import javax.imageio.ImageIO;
-import java.io.IOException;
-import java.io.FileOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.awt.*;
-import java.awt.image.BufferedImage;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.Rectangle2D;
-
-/**
- * Demonstrates how you can use HSLF to convert each slide into a PNG image
- *
- * @author Yegor Kozlov
- */
-public class PPT2PNG {
-
- public static void main(String args[]) throws Exception {
-
- if (args.length == 0) {
- usage();
- return;
- }
-
- int slidenum = -1;
- float scale = 1;
- String file = null;
-
- for (int i = 0; i < args.length; i++) {
- if (args[i].startsWith("-")) {
- if ("-scale".equals(args[i])){
- scale = Float.parseFloat(args[++i]);
- } else if ("-slide".equals(args[i])) {
- slidenum = Integer.parseInt(args[++i]);
- }
- } else {
- file = args[i];
- }
- }
- if(file == null){
- usage();
- return;
- }
-
- FileInputStream is = new FileInputStream(file);
- SlideShow ppt = new SlideShow(is);
- is.close();
-
- Dimension pgsize = ppt.getPageSize();
- int width = (int)(pgsize.width*scale);
- int height = (int)(pgsize.height*scale);
-
- Slide[] slide = ppt.getSlides();
- for (int i = 0; i < slide.length; i++) {
- if (slidenum != -1 && slidenum != (i+1)) continue;
-
- String title = slide[i].getTitle();
- System.out.println("Rendering slide "+slide[i].getSlideNumber() + (title == null ? "" : ": " + title));
-
- BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
- Graphics2D graphics = img.createGraphics();
- graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
- graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
- graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
-
- graphics.setPaint(Color.white);
- graphics.fill(new Rectangle2D.Float(0, 0, width, height));
-
- graphics.scale((double)width/pgsize.width, (double)height/pgsize.height);
-
- slide[i].draw(graphics);
-
- String fname = file.replaceAll("\\.ppt", "-" + (i+1) + ".png");
- FileOutputStream out = new FileOutputStream(fname);
- ImageIO.write(img, "png", out);
- out.close();
- }
- }
-
- private static void usage(){
- System.out.println("Usage: PPT2PNG [-scale <scale> -slide <num>] ppt");
- }
-}
+/* ====================================================================
+ 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.hslf.examples;
+
+import org.apache.poi.hslf.usermodel.*;
+import org.apache.poi.hslf.model.*;
+import org.apache.poi.hslf.record.TextHeaderAtom;
+
+import javax.imageio.ImageIO;
+import java.io.IOException;
+import java.io.FileOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.awt.*;
+import java.awt.image.BufferedImage;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Rectangle2D;
+
+/**
+ * Demonstrates how you can use HSLF to convert each slide into a PNG image
+ *
+ * @author Yegor Kozlov
+ */
+public final class PPT2PNG {
+
+ public static void main(String args[]) throws Exception {
+
+ if (args.length == 0) {
+ usage();
+ return;
+ }
+
+ int slidenum = -1;
+ float scale = 1;
+ String file = null;
+
+ for (int i = 0; i < args.length; i++) {
+ if (args[i].startsWith("-")) {
+ if ("-scale".equals(args[i])){
+ scale = Float.parseFloat(args[++i]);
+ } else if ("-slide".equals(args[i])) {
+ slidenum = Integer.parseInt(args[++i]);
+ }
+ } else {
+ file = args[i];
+ }
+ }
+ if(file == null){
+ usage();
+ return;
+ }
+
+ FileInputStream is = new FileInputStream(file);
+ SlideShow ppt = new SlideShow(is);
+ is.close();
+
+ Dimension pgsize = ppt.getPageSize();
+ int width = (int)(pgsize.width*scale);
+ int height = (int)(pgsize.height*scale);
+
+ Slide[] slide = ppt.getSlides();
+ for (int i = 0; i < slide.length; i++) {
+ if (slidenum != -1 && slidenum != (i+1)) continue;
+
+ String title = slide[i].getTitle();
+ System.out.println("Rendering slide "+slide[i].getSlideNumber() + (title == null ? "" : ": " + title));
+
+ BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
+ Graphics2D graphics = img.createGraphics();
+ graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+ graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
+ graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
+ graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
+
+ graphics.setPaint(Color.white);
+ graphics.fill(new Rectangle2D.Float(0, 0, width, height));
+
+ graphics.scale((double)width/pgsize.width, (double)height/pgsize.height);
+
+ slide[i].draw(graphics);
+
+ String fname = file.replaceAll("\\.ppt", "-" + (i+1) + ".png");
+ FileOutputStream out = new FileOutputStream(fname);
+ ImageIO.write(img, "png", out);
+ out.close();
+ }
+ }
+
+ private static void usage(){
+ System.out.println("Usage: PPT2PNG [-scale <scale> -slide <num>] ppt");
+ }
+}
diff --git a/src/scratchpad/examples/src/org/apache/poi/hslf/examples/TableDemo.java b/src/scratchpad/examples/src/org/apache/poi/hslf/examples/TableDemo.java
index 25ff9ad017..44935c05ac 100755
--- a/src/scratchpad/examples/src/org/apache/poi/hslf/examples/TableDemo.java
+++ b/src/scratchpad/examples/src/org/apache/poi/hslf/examples/TableDemo.java
@@ -1,127 +1,127 @@
-
-/* ====================================================================
- 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.hslf.examples;
-
-import org.apache.poi.hslf.usermodel.SlideShow;
-import org.apache.poi.hslf.usermodel.RichTextRun;
-import org.apache.poi.hslf.model.*;
-
-import java.awt.*;
-import java.io.FileOutputStream;
-
-/**
- * Demonstrates how to create tables
- *
- * @author Yegor Kozlov
- */
-public class TableDemo {
-
- public static void main(String[] args) throws Exception {
-
- //test data for the first taable
- String[][] txt1 = {
- {"INPUT FILE", "NUMBER OF RECORDS"},
- {"Item File", "11,559"},
- {"Vendor File", "502"},
- {"Purchase History File - # of PO\u2019s\r(12/01/04 - 05/31/06)", "12,852"},
- {"Purchase History File - # of PO Lines\r(12/01/04 - 05/31/06)", "53,523" },
- {"Total PO History Spend", "$10,172,038"}
- };
-
- SlideShow ppt = new SlideShow();
-
- Slide slide = ppt.createSlide();
-
- //six rows, two columns
- Table table1 = new Table(6, 2);
- for (int i = 0; i < txt1.length; i++) {
- for (int j = 0; j < txt1[i].length; j++) {
- TableCell cell = table1.getCell(i, j);
- cell.setText(txt1[i][j]);
- RichTextRun rt = cell.getTextRun().getRichTextRuns()[0];
- rt.setFontName("Arial");
- rt.setFontSize(10);
- if(i == 0){
- cell.getFill().setForegroundColor(new Color(227, 227, 227));
- } else {
- rt.setBold(true);
- }
- cell.setVerticalAlignment(TextBox.AnchorMiddle);
- cell.setHorizontalAlignment(TextBox.AlignCenter);
- }
- }
-
- Line border1 = table1.createBorder();
- border1.setLineColor(Color.black);
- border1.setLineWidth(1.0);
- table1.setAllBorders(border1);
-
- table1.setColumnWidth(0, 300);
- table1.setColumnWidth(1, 150);
-
- slide.addShape(table1);
- int pgWidth = ppt.getPageSize().width;
- table1.moveTo((pgWidth - table1.getAnchor().width)/2, 100);
-
- //test data for the second taable
- String[][] txt2 = {
- {"Data Source"},
- {"CAS Internal Metrics - Item Master Summary\r" +
- "CAS Internal Metrics - Vendor Summary\r" +
- "CAS Internal Metrics - PO History Summary"}
- };
-
- //two rows, one column
- Table table2 = new Table(2, 1);
- for (int i = 0; i < txt2.length; i++) {
- for (int j = 0; j < txt2[i].length; j++) {
- TableCell cell = table2.getCell(i, j);
- cell.setText(txt2[i][j]);
- RichTextRun rt = cell.getTextRun().getRichTextRuns()[0];
- rt.setFontSize(10);
- rt.setFontName("Arial");
- if(i == 0){
- cell.getFill().setForegroundColor(new Color(0, 51, 102));
- rt.setFontColor(Color.white);
- rt.setBold(true);
- rt.setFontSize(14);
- cell.setHorizontalAlignment(TextBox.AlignCenter);
- } else {
- rt.setBullet(true);
- rt.setFontSize(12);
- cell.setHorizontalAlignment(TextBox.AlignLeft);
- }
- cell.setVerticalAlignment(TextBox.AnchorMiddle);
- }
- }
- table2.setColumnWidth(0, 300);
- table2.setRowHeight(0, 30);
- table2.setRowHeight(1, 70);
-
- Line border2 = table2.createBorder();
- table2.setOutsideBorders(border2);
-
- slide.addShape(table2);
- table2.moveTo(200, 400);
-
- FileOutputStream out = new FileOutputStream("hslf-table.ppt");
- ppt.write(out);
- out.close();
-
- }
-}
+/* ====================================================================
+ 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.hslf.examples;
+
+import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hslf.usermodel.RichTextRun;
+import org.apache.poi.hslf.model.*;
+
+import java.awt.*;
+import java.io.FileOutputStream;
+
+/**
+ * Demonstrates how to create tables
+ *
+ * @author Yegor Kozlov
+ */
+public final class TableDemo {
+
+ public static void main(String[] args) throws Exception {
+
+ //test data for the first taable
+ String[][] txt1 = {
+ {"INPUT FILE", "NUMBER OF RECORDS"},
+ {"Item File", "11,559"},
+ {"Vendor File", "502"},
+ {"Purchase History File - # of PO\u2019s\r(12/01/04 - 05/31/06)", "12,852"},
+ {"Purchase History File - # of PO Lines\r(12/01/04 - 05/31/06)", "53,523" },
+ {"Total PO History Spend", "$10,172,038"}
+ };
+
+ SlideShow ppt = new SlideShow();
+
+ Slide slide = ppt.createSlide();
+
+ //six rows, two columns
+ Table table1 = new Table(6, 2);
+ for (int i = 0; i < txt1.length; i++) {
+ for (int j = 0; j < txt1[i].length; j++) {
+ TableCell cell = table1.getCell(i, j);
+ cell.setText(txt1[i][j]);
+ RichTextRun rt = cell.getTextRun().getRichTextRuns()[0];
+ rt.setFontName("Arial");
+ rt.setFontSize(10);
+ if(i == 0){
+ cell.getFill().setForegroundColor(new Color(227, 227, 227));
+ } else {
+ rt.setBold(true);
+ }
+ cell.setVerticalAlignment(TextBox.AnchorMiddle);
+ cell.setHorizontalAlignment(TextBox.AlignCenter);
+ }
+ }
+
+ Line border1 = table1.createBorder();
+ border1.setLineColor(Color.black);
+ border1.setLineWidth(1.0);
+ table1.setAllBorders(border1);
+
+ table1.setColumnWidth(0, 300);
+ table1.setColumnWidth(1, 150);
+
+ slide.addShape(table1);
+ int pgWidth = ppt.getPageSize().width;
+ table1.moveTo((pgWidth - table1.getAnchor().width)/2, 100);
+
+ //test data for the second taable
+ String[][] txt2 = {
+ {"Data Source"},
+ {"CAS Internal Metrics - Item Master Summary\r" +
+ "CAS Internal Metrics - Vendor Summary\r" +
+ "CAS Internal Metrics - PO History Summary"}
+ };
+
+ //two rows, one column
+ Table table2 = new Table(2, 1);
+ for (int i = 0; i < txt2.length; i++) {
+ for (int j = 0; j < txt2[i].length; j++) {
+ TableCell cell = table2.getCell(i, j);
+ cell.setText(txt2[i][j]);
+ RichTextRun rt = cell.getTextRun().getRichTextRuns()[0];
+ rt.setFontSize(10);
+ rt.setFontName("Arial");
+ if(i == 0){
+ cell.getFill().setForegroundColor(new Color(0, 51, 102));
+ rt.setFontColor(Color.white);
+ rt.setBold(true);
+ rt.setFontSize(14);
+ cell.setHorizontalAlignment(TextBox.AlignCenter);
+ } else {
+ rt.setBullet(true);
+ rt.setFontSize(12);
+ cell.setHorizontalAlignment(TextBox.AlignLeft);
+ }
+ cell.setVerticalAlignment(TextBox.AnchorMiddle);
+ }
+ }
+ table2.setColumnWidth(0, 300);
+ table2.setRowHeight(0, 30);
+ table2.setRowHeight(1, 70);
+
+ Line border2 = table2.createBorder();
+ table2.setOutsideBorders(border2);
+
+ slide.addShape(table2);
+ table2.moveTo(200, 400);
+
+ FileOutputStream out = new FileOutputStream("hslf-table.ppt");
+ ppt.write(out);
+ out.close();
+
+ }
+}
diff --git a/src/scratchpad/examples/src/org/apache/poi/hwpf/Word2Forrest.java b/src/scratchpad/examples/src/org/apache/poi/hwpf/Word2Forrest.java
index 122533f9ec..82d3a8a230 100644
--- a/src/scratchpad/examples/src/org/apache/poi/hwpf/Word2Forrest.java
+++ b/src/scratchpad/examples/src/org/apache/poi/hwpf/Word2Forrest.java
@@ -1,4 +1,3 @@
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@@ -15,7 +14,7 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
+
package org.apache.poi.hwpf;
import org.apache.poi.hwpf.HWPFDocument;
@@ -24,7 +23,7 @@ import org.apache.poi.hwpf.model.*;
import java.io.*;
-public class Word2Forrest
+public final class Word2Forrest
{
Writer _out;
HWPFDocument _doc;