You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2015/07/26 01:26:37 UTC
svn commit: r1692670 - in
/poi/site/src/documentation/content/xdocs/slideshow: how-to-shapes.xml
quick-guide.xml xslf-cookbook.xml
Author: kiwiwings
Date: Sat Jul 25 23:26:37 2015
New Revision: 1692670
URL: http://svn.apache.org/r1692670
Log:
Adapt docu to common_sl changes
Modified:
poi/site/src/documentation/content/xdocs/slideshow/how-to-shapes.xml
poi/site/src/documentation/content/xdocs/slideshow/quick-guide.xml
poi/site/src/documentation/content/xdocs/slideshow/xslf-cookbook.xml
Modified: poi/site/src/documentation/content/xdocs/slideshow/how-to-shapes.xml
URL: http://svn.apache.org/viewvc/poi/site/src/documentation/content/xdocs/slideshow/how-to-shapes.xml?rev=1692670&r1=1692669&r2=1692670&view=diff
==============================================================================
--- poi/site/src/documentation/content/xdocs/slideshow/how-to-shapes.xml (original)
+++ poi/site/src/documentation/content/xdocs/slideshow/how-to-shapes.xml Sat Jul 25 23:26:37 2015
@@ -54,13 +54,13 @@
<section><title>New Presentation</title>
<source>
//create a new empty slide show
- SlideShow ppt = new SlideShow();
-
+ HSLFSlideShow ppt = new HSLFSlideShow();
+
//add first slide
- Slide s1 = ppt.createSlide();
-
+ HSLFSlide s1 = ppt.createSlide();
+
//add second slide
- Slide s2 = ppt.createSlide();
+ HSLFSlide s2 = ppt.createSlide();
//save changes in a file
FileOutputStream out = new FileOutputStream("slideshow.ppt");
@@ -71,7 +71,7 @@
<anchor id="PageSize"/>
<section><title>How to retrieve or change slide size</title>
<source>
- SlideShow ppt = new SlideShow(new HSLFSlideShow("slideshow.ppt"));
+ HSLFSlideShow ppt = new HSLFSlideShow(new HSLFSlideShowImpl("slideshow.ppt"));
//retrieve page size. Coordinates are expressed in points (72 dpi)
java.awt.Dimension pgsize = ppt.getPageSize();
int pgx = pgsize.width; //slide width
@@ -91,33 +91,31 @@
The following code demonstrates how to iterate over shapes for each slide.
</p>
<source>
- SlideShow ppt = new SlideShow(new HSLFSlideShow("slideshow.ppt"));
- //get slides
- Slide[] slide = ppt.getSlides();
- for (int i = 0; i < slide.length; i++){
- Shape[] sh = slide[i].getShapes();
- for (int j = 0; j < sh.length; j++){
- //name of the shape
- String name = sh[j].getShapeName();
-
- //shapes's anchor which defines the position of this shape in the slide
- java.awt.Rectangle anchor = sh[j].getAnchor();
-
- if (sh[j] instanceof Line){
- Line line = (Line)sh[j];
- //work with Line
- } else if (sh[j] instanceof AutoShape){
- AutoShape shape = (AutoShape)sh[j];
- //work with AutoShape
- } else if (sh[j] instanceof TextBox){
- TextBox shape = (TextBox)sh[j];
- //work with TextBox
- } else if (sh[j] instanceof Picture){
- Picture shape = (Picture)sh[j];
- //work with Picture
- }
+ HSLFSlideShow ppt = new HSLFSlideShow(new HSLFSlideShowImpl("slideshow.ppt"));
+ // get slides
+ for (HSLFSlide slide : ppt.getSlides()) {
+ for (HSLFShape sh : slide.getShapes()) {
+ // name of the shape
+ String name = sh.getShapeName();
+
+ // shapes's anchor which defines the position of this shape in the slide
+ java.awt.Rectangle anchor = sh.getAnchor();
+
+ if (sh instanceof Line) {
+ Line line = (Line) sh;
+ // work with Line
+ } else if (sh instanceof HSLFAutoShape) {
+ HSLFAutoShape shape = (HSLFAutoShape) sh;
+ // work with AutoShape
+ } else if (sh instanceof HSLFTextBox) {
+ HSLFTextBox shape = (HSLFTextBox) sh;
+ // work with TextBox
+ } else if (sh instanceof HSLFPictureShape) {
+ HSLFPictureShape shape = (HSLFPictureShape) sh;
+ // work with Picture
+ }
+ }
}
- }
</source>
</section>
<anchor id="Shapes"/>
@@ -135,51 +133,51 @@
corner of the slide. Distances in the drawing layer are measured in points (72 points = 1 inch).
</p>
<source>
- SlideShow ppt = new SlideShow();
-
- Slide slide = ppt.createSlide();
-
- //Line shape
- Line line = new Line();
- line.setAnchor(new java.awt.Rectangle(50, 50, 100, 20));
- line.setLineColor(new Color(0, 128, 0));
- line.setLineStyle(Line.LINE_DOUBLE);
- slide.addShape(line);
-
- //TextBox
- TextBox txt = new TextBox();
- txt.setText("Hello, World!");
- txt.setAnchor(new java.awt.Rectangle(300, 100, 300, 50));
-
- //use RichTextRun to work with the text format
- RichTextRun rt = txt.getTextRun().getRichTextRuns()[0];
- rt.setFontSize(32);
- rt.setFontName("Arial");
- rt.setBold(true);
- rt.setItalic(true);
- rt.setUnderlined(true);
- rt.setFontColor(Color.red);
- rt.setAlignment(TextBox.AlignRight);
-
- slide.addShape(txt);
-
- //Autoshape
- //32-point star
- AutoShape sh1 = new AutoShape(ShapeTypes.Star32);
- sh1.setAnchor(new java.awt.Rectangle(50, 50, 100, 200));
- sh1.setFillColor(Color.red);
- slide.addShape(sh1);
-
- //Trapezoid
- AutoShape sh2 = new AutoShape(ShapeTypes.Trapezoid);
- sh2.setAnchor(new java.awt.Rectangle(150, 150, 100, 200));
- sh2.setFillColor(Color.blue);
- slide.addShape(sh2);
-
- FileOutputStream out = new FileOutputStream("slideshow.ppt");
- ppt.write(out);
- out.close();
-
+ HSLFSlideShow ppt = new HSLFSlideShow();
+
+ HSLFSlide slide = ppt.createSlide();
+
+ //Line shape
+ Line line = new Line();
+ line.setAnchor(new java.awt.Rectangle(50, 50, 100, 20));
+ line.setLineColor(new Color(0, 128, 0));
+ line.setLineCompound(LineCompound.DOUBLE);
+ slide.addShape(line);
+
+ //TextBox
+ HSLFTextBox txt = new HSLFTextBox();
+ txt.setText("Hello, World!");
+ txt.setAnchor(new java.awt.Rectangle(300, 100, 300, 50));
+
+ // use TextRun to work with the text format
+ HSLFTextParagraph tp = txt.getTextParagraphs().get(0);
+ tp.setAlignment(TextAlign.RIGHT);
+ HSLFTextRun rt = tp.getTextRuns().get(0);
+ rt.setFontSize(32.);
+ rt.setFontFamily("Arial");
+ rt.setBold(true);
+ rt.setItalic(true);
+ rt.setUnderlined(true);
+ rt.setFontColor(Color.red);
+
+ slide.addShape(txt);
+
+ // Autoshape
+ // 32-point star
+ HSLFAutoShape sh1 = new HSLFAutoShape(ShapeType.STAR_32);
+ sh1.setAnchor(new java.awt.Rectangle(50, 50, 100, 200));
+ sh1.setFillColor(Color.red);
+ slide.addShape(sh1);
+
+ //Trapezoid
+ HSLFAutoShape sh2 = new HSLFAutoShape(ShapeType.TRAPEZOID);
+ sh2.setAnchor(new java.awt.Rectangle(150, 150, 100, 200));
+ sh2.setFillColor(Color.blue);
+ slide.addShape(sh2);
+
+ FileOutputStream out = new FileOutputStream("slideshow.ppt");
+ ppt.write(out);
+ out.close();
</source>
</section>
<anchor id="Pictures"/>
@@ -197,79 +195,77 @@
</ul>
<source>
- SlideShow ppt = new SlideShow(new HSLFSlideShow("slideshow.ppt"));
+ HSLFSlideShow ppt = new HSLFSlideShow(new HSLFSlideShowImpl("slideshow.ppt"));
- //extract all pictures contained in the presentation
- PictureData[] pdata = ppt.getPictureData();
- for (int i = 0; i < pdata.length; i++){
- PictureData pict = pdata[i];
-
- // picture data
- byte[] data = pict.getData();
-
- int type = pict.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;
- default: continue;
- }
- FileOutputStream out = new FileOutputStream("pict_"+i + ext);
- out.write(data);
- out.close();
-
- }
-
- // add a new picture to this slideshow and insert it in a new slide
- int idx = ppt.addPicture(new File("clock.jpg"), Picture.JPEG);
-
- Picture pict = new Picture(idx);
-
- //set image position in the slide
- pict.setAnchor(new java.awt.Rectangle(100, 100, 300, 200));
-
- Slide slide = ppt.createSlide();
- slide.addShape(pict);
-
- //now retrieve pictures containes in the first slide and save them on disk
- slide = ppt.getSlides()[0];
- Shape[] sh = slide.getShapes();
- for (int i = 0; i < sh.length; i++){
- if (sh[i] instanceof Picture){
- Picture pict = (Picture)sh[i];
- PictureData pictData = pict.getPictureData();
- byte[] data = pictData.getData();
- int type = pictData.getType();
- if (type == Picture.JPEG){
- FileOutputStream out = new FileOutputStream("slide0_"+i+".jpg");
- out.write(data);
- out.close();
- } else if (type == Picture.PNG){
- FileOutputStream out = new FileOutputStream("slide0_"+i+".png");
+ // extract all pictures contained in the presentation
+ int idx = 1;
+ for (HSLFPictureData pict : ppt.getPictureData()) {
+ // picture data
+ byte[] data = pict.getData();
+
+ int type = pict.getType();
+ String ext;
+ switch (type) {
+ case HSLFPictureShape.JPEG: ext = ".jpg"; break;
+ case HSLFPictureShape.PNG: ext = ".png"; break;
+ case HSLFPictureShape.WMF: ext = ".wmf"; break;
+ case HSLFPictureShape.EMF: ext = ".emf"; break;
+ case HSLFPictureShape.PICT: ext = ".pict"; break;
+ default: continue;
+ }
+ FileOutputStream out = new FileOutputStream("pict_" + idx + ext);
out.write(data);
out.close();
- }
+ idx++;
}
- }
- FileOutputStream out = new FileOutputStream("slideshow.ppt");
- ppt.write(out);
- out.close();
+ // add a new picture to this slideshow and insert it in a new slide
+ idx = ppt.addPicture(new File("clock.jpg"), HSLFPictureShape.JPEG);
+ HSLFPictureShape pictNew = new HSLFPictureShape(idx);
+
+ // set image position in the slide
+ pictNew.setAnchor(new java.awt.Rectangle(100, 100, 300, 200));
+
+ HSLFSlide slide = ppt.createSlide();
+ slide.addShape(pictNew);
+
+ // now retrieve pictures containes in the first slide and save them on disk
+ idx = 1;
+ slide = ppt.getSlides().get(0);
+ for (HSLFShape sh : slide.getShapes()) {
+ if (sh instanceof HSLFPictureShape) {
+ HSLFPictureShape pict = (HSLFPictureShape) sh;
+ HSLFPictureData pictData = pict.getPictureData();
+ byte[] data = pictData.getData();
+ int type = pictData.getType();
+ if (type == HSLFPictureShape.JPEG) {
+ FileOutputStream out = new FileOutputStream("slide0_" + idx + ".jpg");
+ out.write(data);
+ out.close();
+ } else if (type == HSLFPictureShape.PNG) {
+ FileOutputStream out = new FileOutputStream("slide0_" + idx + ".png");
+ out.write(data);
+ out.close();
+ }
+ idx++;
+ }
+ }
+
+ FileOutputStream out = new FileOutputStream("slideshow.ppt");
+ ppt.write(out);
+ out.close();
</source>
</section>
<anchor id="SlideTitle"/>
<section><title>How to set slide title</title>
<source>
- SlideShow ppt = new SlideShow();
- Slide slide = ppt.createSlide();
- TextBox title = slide.addTitle();
+ HSLFSlideShow ppt = new HSLFSlideShow();
+ HSLFSlide slide = ppt.createSlide();
+ HSLFTextBox title = slide.addTitle();
title.setText("Hello, World!");
-
- //save changes
+
+ // save changes
FileOutputStream out = new FileOutputStream("slideshow.ppt");
ppt.write(out);
out.close();
@@ -285,90 +281,86 @@
<anchor id="Fill"/>
<section><title>How to modify background of a slide master</title>
<source>
- SlideShow ppt = new SlideShow();
- SlideMaster master = ppt.getSlidesMasters()[0];
+ HSLFSlideShow ppt = new HSLFSlideShow();
+ HSLFSlideMaster master = ppt.getSlideMasters().get(0);
- Fill fill = master.getBackground().getFill();
- int idx = ppt.addPicture(new File("background.png"), Picture.PNG);
- fill.setFillType(Fill.FILL_PICTURE);
- fill.setPictureData(idx);
+ HSLFFill fill = master.getBackground().getFill();
+ int idx = ppt.addPicture(new File("background.png"), HSLFPictureShape.PNG);
+ fill.setFillType(HSLFFill.FILL_PICTURE);
+ fill.setPictureData(idx);
</source>
</section>
<section><title>How to modify background of a slide</title>
<source>
- SlideShow ppt = new SlideShow();
- Slide slide = ppt.createSlide();
-
- //This slide has its own background.
- //Without this line it will use master's background.
- slide.setFollowMasterBackground(false);
- Fill fill = slide.getBackground().getFill();
- int idx = ppt.addPicture(new File("background.png"), Picture.PNG);
- fill.setFillType(Fill.FILL_PATTERN);
- fill.setPictureData(idx);
+ HSLFSlideShow ppt = new HSLFSlideShow();
+ HSLFSlide slide = ppt.createSlide();
+
+ // This slide has its own background.
+ // Without this line it will use master's background.
+ slide.setFollowMasterBackground(false);
+ HSLFFill fill = slide.getBackground().getFill();
+ int idx = ppt.addPicture(new File("background.png"), HSLFPictureShape.PNG);
+ fill.setFillType(HSLFFill.FILL_PATTERN);
+ fill.setPictureData(idx);
</source>
</section>
<section><title>How to modify background of a shape</title>
<source>
- SlideShow ppt = new SlideShow();
- Slide slide = ppt.createSlide();
-
- Shape shape = new AutoShape(ShapeTypes.Rectangle);
- shape.setAnchor(new java.awt.Rectangle(100, 100, 200, 200));
- Fill fill = shape.getFill();
- fill.setFillType(Fill.FILL_SHADE);
- fill.setBackgroundColor(Color.red);
- fill.setForegroundColor(Color.green);
-
- slide.addShape(shape);
+ HSLFSlideShow ppt = new HSLFSlideShow();
+ HSLFSlide slide = ppt.createSlide();
+
+ HSLFShape shape = new HSLFAutoShape(ShapeType.RECT);
+ shape.setAnchor(new java.awt.Rectangle(100, 100, 200, 200));
+ HSLFFill fill = shape.getFill();
+ fill.setFillType(HSLFFill.FILL_SHADE);
+ fill.setBackgroundColor(Color.red);
+ fill.setForegroundColor(Color.green);
+
+ slide.addShape(shape);
</source>
</section>
<anchor id="Bullets"/>
<section><title>How to create bulleted lists</title>
<source>
- SlideShow ppt = new SlideShow();
+ HSLFSlideShow ppt = new HSLFSlideShow();
- Slide slide = ppt.createSlide();
+ HSLFSlide 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();
+ HSLFTextBox shape = new HSLFTextBox();
+ HSLFTextParagraph tp = shape.getTextParagraphs().get(0);
+ tp.setBullet(true);
+ tp.setBulletChar('\u263A'); //bullet character
+ tp.setIndent(0.); //bullet offset
+ tp.setLeftMargin(50.); //text offset (should be greater than bullet offset)
+ HSLFTextRun rt = tp.getTextRuns().get(0);
+ shape.setText(
+ "January\r" +
+ "February\r" +
+ "March\r" +
+ "April");
+ rt.setFontSize(42.);
+ 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();
</source>
</section>
<anchor id="Hyperlinks"/>
<section><title>How to read hyperlinks from a slide show</title>
<source>
FileInputStream is = new FileInputStream("slideshow.ppt");
- SlideShow ppt = new SlideShow(is);
+ HSLFSlideShow ppt = new HSLFSlideShow(is);
is.close();
- Slide[] slide = ppt.getSlides();
- for (int j = 0; j < slide.length; j++) {
-
+ for (HSLFSlide slide : ppt.getSlides()) {
//read 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];
+ for (List<HSLFTextParagraph> txt : slide.getTextParagraphs()) {
+ String text = HSLFTextParagraph.getText(txt);
+ for (HSLFHyperlink link : HSLFHyperlink.find(txt)) {
String title = link.getTitle();
String address = link.getAddress();
String substring = text.substring(link.getStartIndex(), link.getEndIndex()-1); //in ppt end index is inclusive
@@ -378,9 +370,8 @@
//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
- Shape[] sh = slide[j].getShapes();
- for (int k = 0; k < sh.length; k++) {
- Hyperlink link = sh[k].getHyperlink();
+ for (HSLFShape sh : slide.getShapes()) {
+ HSLFHyperlink link = sh.getHyperlink();
if(link != null) {
String title = link.getTitle();
String address = link.getAddress();
@@ -392,128 +383,119 @@
<anchor id="Tables"/>
<section><title>How to create tables</title>
<source>
- //table data
- String[][] data = {
- {"INPUT FILE", "NUMBER OF RECORDS"},
- {"Item File", "11,559"},
- {"Vendor File", "300"},
- {"Purchase History File", "10,000"},
- {"Total # of requisitions", "10,200,038"}
- };
-
- SlideShow ppt = new SlideShow();
-
- Slide slide = ppt.createSlide();
- //create a table of 5 rows and 2 columns
- Table table = new Table(5, 2);
- for (int i = 0; i < data.length; i++) {
- for (int j = 0; j < data[i].length; j++) {
- TableCell cell = table.getCell(i, j);
- cell.setText(data[i][j]);
-
- RichTextRun rt = cell.getTextRun().getRichTextRuns()[0];
- rt.setFontName("Arial");
- rt.setFontSize(10);
-
- cell.setVerticalAlignment(TextBox.AnchorMiddle);
- cell.setHorizontalAlignment(TextBox.AlignCenter);
- }
- }
-
- //set table borders
- Line border = table.createBorder();
- border.setLineColor(Color.black);
- border.setLineWidth(1.0);
- table.setAllBorders(border);
-
- //set width of the 1st column
- table.setColumnWidth(0, 300);
- //set width of the 2nd column
- table.setColumnWidth(1, 150);
-
- slide.addShape(table);
- table.moveTo(100, 100);
-
- FileOutputStream out = new FileOutputStream("hslf-table.ppt");
- ppt.write(out);
- out.close();
-
+ //table data
+ String[][] data = {
+ {"INPUT FILE", "NUMBER OF RECORDS"},
+ {"Item File", "11,559"},
+ {"Vendor File", "300"},
+ {"Purchase History File", "10,000"},
+ {"Total # of requisitions", "10,200,038"}
+ };
+
+ HSLFSlideShow ppt = new HSLFSlideShow();
+
+ HSLFSlide slide = ppt.createSlide();
+ //create a table of 5 rows and 2 columns
+ HSLFTable table = new HSLFTable(5, 2);
+ for (int i = 0; i < data.length; i++) {
+ for (int j = 0; j < data[i].length; j++) {
+ HSLFTableCell cell = table.getCell(i, j);
+ cell.setText(data[i][j]);
+
+ HSLFTextRun rt = cell.getTextParagraphs().get(0).getTextRuns().get(0);
+ rt.setFontFamily("Arial");
+ rt.setFontSize(10.);
+
+ cell.setVerticalAlignment(VerticalAlignment.MIDDLE);
+ cell.setHorizontalCentered(true);
+ }
+ }
+
+ //set table borders
+ Line border = table.createBorder();
+ border.setLineColor(Color.black);
+ border.setLineWidth(1.0);
+ table.setAllBorders(border);
+
+ //set width of the 1st column
+ table.setColumnWidth(0, 300);
+ //set width of the 2nd column
+ table.setColumnWidth(1, 150);
+
+ slide.addShape(table);
+ table.moveTo(100, 100);
+
+ FileOutputStream out = new FileOutputStream("hslf-table.ppt");
+ ppt.write(out);
+ out.close();
</source>
</section>
<anchor id="RemoveShape"/>
<section><title>How to remove shapes from a slide</title>
<source>
-
- Shape[] shape = slide.getShapes();
- for (int i = 0; i < shape.length; i++) {
-
- //remove the shape
- boolean ok = slide.removeShape(shape[i]);
- if(ok){
- //the shape was removed. Do something.
- }
+ for (HSLFShape shape : slide.getShapes()) {
+ // remove the shape
+ boolean ok = slide.removeShape(shape);
+ if (ok) {
+ // the shape was removed. Do something.
}
+ }
</source>
</section>
<anchor id="OLE"/>
<section><title>How to retrieve embedded OLE objects</title>
<source>
-
- Shape[] shape = slide.getShapes();
- for (int i = 0; i < shape.length; i++) {
- if (shape[i] instanceof OLEShape) {
- OLEShape ole = (OLEShape) shape[i];
- ObjectData data = ole.getObjectData();
- String name = ole.getInstanceName();
- if ("Worksheet".equals(name)) {
- HSSFWorkbook wb = new HSSFWorkbook(data.getData());
- } else if ("Document".equals(name)) {
- HWPFDocument doc = new HWPFDocument(data.getData());
- }
+ for (HSLFShape shape : slide.getShapes()) {
+ if (shape instanceof OLEShape) {
+ OLEShape ole = (OLEShape) shape;
+ HSLFObjectData data = ole.getObjectData();
+ String name = ole.getInstanceName();
+ if ("Worksheet".equals(name)) {
+ HSSFWorkbook wb = new HSSFWorkbook(data.getData());
+ } else if ("Document".equals(name)) {
+ HWPFDocument doc = new HWPFDocument(data.getData());
}
}
+ }
</source>
</section>
<anchor id="Sound"/>
<section><title>How to retrieve embedded sounds</title>
<source>
+ FileInputStream is = new FileInputStream(args[0]);
+ HSLFSlideShow ppt = new HSLFSlideShow(is);
+ is.close();
- FileInputStream is = new FileInputStream(args[0]);
- SlideShow ppt = new SlideShow(is);
- is.close();
-
- SoundData[] sound = ppt.getSoundData();
- for (int i = 0; i < sound.length; i++) {
- //save *WAV sounds on disk
- if(sound[i].getSoundType().equals(".WAV")){
- FileOutputStream out = new FileOutputStream(sound[i].getSoundName());
- out.write(sound[i].getData());
- out.close();
- }
+ for (HSLFSoundData sound : ppt.getSoundData()) {
+ // save *WAV sounds on disk
+ if (sound.getSoundType().equals(".WAV")) {
+ FileOutputStream out = new FileOutputStream(sound.getSoundName());
+ out.write(sound.getData());
+ out.close();
}
+ }
</source>
</section>
<anchor id="Freeform"/>
<section><title>How to create shapes of arbitrary geometry</title>
<source>
+ HSLFSlideShow ppt = new HSLFSlideShow();
+ HSLFSlide slide = ppt.createSlide();
- SlideShow ppt = new SlideShow();
- Slide slide = ppt.createSlide();
-
- java.awt.geom.GeneralPath path = new java.awt.geom.GeneralPath();
- path.moveTo(100, 100);
- path.lineTo(200, 100);
- path.curveTo(50, 45, 134, 22, 78, 133);
- path.curveTo(10, 45, 134, 56, 78, 100);
- path.lineTo(100, 200);
- path.closePath();
-
- Freeform shape = new Freeform();
- shape.setPath(path);
- slide.addShape(shape);
+ java.awt.geom.GeneralPath path = new java.awt.geom.GeneralPath();
+ path.moveTo(100, 100);
+ path.lineTo(200, 100);
+ path.curveTo(50, 45, 134, 22, 78, 133);
+ path.curveTo(10, 45, 134, 56, 78, 100);
+ path.lineTo(100, 200);
+ path.closePath();
+
+ HSLFFreeformShape shape = new HSLFFreeformShape();
+ shape.setPath(path);
+ slide.addShape(shape);
</source>
</section>
@@ -524,52 +506,55 @@
Some features like clipping, drawing of images are not yet supported.
</warning>
<source>
- SlideShow ppt = new SlideShow();
- Slide slide = ppt.createSlide();
+ HSLFSlideShow ppt = new HSLFSlideShow();
+ HSLFSlide slide = ppt.createSlide();
- //draw a simple bar graph
- //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),
- };
-
- //all objects are drawn into a shape group so we need to create one
-
- ShapeGroup group = new ShapeGroup();
- //define position of the drawing in the slide
- Rectangle bounds = new java.awt.Rectangle(200, 100, 350, 300);
- //if you want to draw in the entire slide area then define the anchor as follows:
- //Dimension pgsize = ppt.getPageSize();
- //java.awt.Rectangle bounds = new java.awt.Rectangle(0, 0, pgsize.width, pgsize.height);
-
- group.setAnchor(bounds);
- slide.addShape(group);
-
- //draw a simple bar chart
- Graphics2D graphics = new PPGraphics2D(group);
- 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;
- }
+ // draw a simple bar graph
+ // 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),
+ };
+
+ // all objects are drawn into a shape group so we need to create one
+
+ HSLFGroupShape group = new HSLFGroupShape();
+ // define position of the drawing in the slide
+ Rectangle bounds = new java.awt.Rectangle(200, 100, 350, 300);
+ // if you want to draw in the entire slide area then define the anchor
+ // as follows:
+ // Dimension pgsize = ppt.getPageSize();
+ // java.awt.Rectangle bounds = new java.awt.Rectangle(0, 0,
+ // pgsize.width, pgsize.height);
+
+ group.setAnchor(bounds);
+ slide.addShape(group);
+
+ // draw a simple bar chart
+ Graphics2D graphics = new PPGraphics2D(group);
+ 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);
- graphics.setFont(new Font("Arial", Font.BOLD, 14));
- graphics.draw(bounds);
- graphics.drawString("Performance", x + 70, y + 40);
-
- FileOutputStream out = new FileOutputStream("hslf-graphics2d.ppt");
- ppt.write(out);
- out.close();
+ 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);
+ FileOutputStream out = new FileOutputStream("hslf-graphics2d.ppt");
+ ppt.write(out);
+ out.close();
</source>
</section>
@@ -593,30 +578,31 @@
<li>Only Bitmap images (PNG, JPEG, DIB) can be rendered in Java</li>
</ul>
<source>
- FileInputStream is = new FileInputStream("slideshow.ppt");
- SlideShow ppt = new SlideShow(is);
- is.close();
-
- Dimension pgsize = ppt.getPageSize();
-
- Slide[] slide = ppt.getSlides();
- for (int i = 0; i < slide.length; i++) {
-
- BufferedImage img = new BufferedImage(pgsize.width, pgsize.height, BufferedImage.TYPE_INT_RGB);
- Graphics2D graphics = img.createGraphics();
- //clear the drawing area
- graphics.setPaint(Color.white);
- graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height));
-
- //render
- slide[i].draw(graphics);
-
- //save the output
- FileOutputStream out = new FileOutputStream("slide-" + (i+1) + ".png");
- javax.imageio.ImageIO.write(img, "png", out);
- out.close();
- }
+ FileInputStream is = new FileInputStream("slideshow.ppt");
+ HSLFSlideShow ppt = new HSLFSlideShow(is);
+ is.close();
+
+ Dimension pgsize = ppt.getPageSize();
+
+ int idx = 1;
+ for (HSLFSlide slide : ppt.getSlides()) {
+ BufferedImage img = new BufferedImage(pgsize.width, pgsize.height, BufferedImage.TYPE_INT_RGB);
+ Graphics2D graphics = img.createGraphics();
+ // clear the drawing area
+ graphics.setPaint(Color.white);
+ graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height));
+
+ // render
+ slide.draw(graphics);
+
+ // save the output
+ FileOutputStream out = new FileOutputStream("slide-" + idx + ".png");
+ javax.imageio.ImageIO.write(img, "png", out);
+ out.close();
+
+ idx++;
+ }
</source>
</section>
@@ -624,43 +610,39 @@
<anchor id="HeadersFooters"/>
<section><title>How to extract Headers / Footers from an existing presentation</title>
<source>
+ FileInputStream is = new FileInputStream("slideshow.ppt");
+ HSLFSlideShow ppt = new HSLFSlideShow(is);
+ is.close();
- FileInputStream is = new FileInputStream("slideshow.ppt");
- SlideShow ppt = new SlideShow(is);
- is.close();
- Slide[] slides = ppt.getSlides();
-
- //presentation-scope headers / footers
- HeadersFooters hdd = ppt.getSlideHeadersFooters();
- if(hdd.isFooterVisible()) {
- String footerText = hdd.getFooterText();
- }
-
- //per-slide headers / footers
- for (int i=0; i < slides.length; i++){
- HeadersFooters hdd2 = slides[i].getHeadersFooters();
- if(hdd2.isFooterVisible()) {
- String footerText = hdd2.getFooterText();
- }
- if(hdd2.isUserDateVisible()) {
- String customDate = hdd2.getDateTimeText();
- }
- if(hdd2.isSlideNumberVisible()){
- int slideNUm = slides[i].getSlideNumber();
- }
+ // presentation-scope headers / footers
+ HeadersFooters hdd = ppt.getSlideHeadersFooters();
+ if (hdd.isFooterVisible()) {
+ String footerText = hdd.getFooterText();
+ }
- }
+ // per-slide headers / footers
+ for (HSLFSlide slide : ppt.getSlides()) {
+ HeadersFooters hdd2 = slide.getHeadersFooters();
+ if (hdd2.isFooterVisible()) {
+ String footerText = hdd2.getFooterText();
+ }
+ if (hdd2.isUserDateVisible()) {
+ String customDate = hdd2.getDateTimeText();
+ }
+ if (hdd2.isSlideNumberVisible()) {
+ int slideNUm = slide.getSlideNumber();
+ }
+ }
</source>
</section>
<section><title>How to set Headers / Footers</title>
<source>
+ HSLFSlideShow ppt = new HSLFSlideShow();
- SlideShow ppt = new SlideShow();
-
- //presentation-scope headers / footers
- HeadersFooters hdd = ppt.getSlideHeadersFooters();
- hdd.setSlideNumberVisible(true);
- hdd.setFootersText("Created by POI-HSLF");
+ // presentation-scope headers / footers
+ HeadersFooters hdd = ppt.getSlideHeadersFooters();
+ hdd.setSlideNumberVisible(true);
+ hdd.setFootersText("Created by POI-HSLF");
</source>
</section>
</section>
Modified: poi/site/src/documentation/content/xdocs/slideshow/quick-guide.xml
URL: http://svn.apache.org/viewvc/poi/site/src/documentation/content/xdocs/slideshow/quick-guide.xml?rev=1692670&r1=1692669&r2=1692670&view=diff
==============================================================================
--- poi/site/src/documentation/content/xdocs/slideshow/quick-guide.xml (original)
+++ poi/site/src/documentation/content/xdocs/slideshow/quick-guide.xml Sat Jul 25 23:26:37 2015
@@ -39,20 +39,20 @@ from both.
</section>
<section><title>Specific Text Extraction</title>
- <p>To get specific bits of text, first create a <code>org.apache.poi.hslf.usermodel.SlideShow</code>
-(from a <code>org.apache.poi.hslf.HSLFSlideShow</code>, which accepts a file or an input
+ <p>To get specific bits of text, first create a <code>org.apache.poi.hslf.usermodel.HSLFSlideShow</code>
+(from a <code>org.apache.poi.hslf.usermodel.HSLFSlideShowImpl</code>, which accepts a file or an input
stream). Use <code>getSlides()</code> and <code>getNotes()</code> to get the slides and notes.
These can be queried to get their page ID (though they should be returned
in the right order).</p>
- <p>You can then call <code>getTextRuns()</code> on these, to get
-their blocks of text. (One TextRun normally holds all the text in a
+ <p>You can then call <code>getTextParagraphs()</code> on these, to get
+their blocks of text. (A list of <code>HSLFTextParagraph</code> normally holds all the text in a
given area of the page, eg in the title bar, or in a box).
-From the <code>TextRun</code>, you can extract the text, and check
-what type of text it is (eg Body, Title). You can allso call
-<code>getRichTextRuns()</code>, which will return the
-<code>RichTextRun</code>s that make up the <code>TextRun</code>. A
-<code>RichTextRun</code> is made up of a sequence of text, all having the
-same character and paragraph formatting.
+From the <code>HSLFTextParagraph</code>, you can extract the text, and check
+what type of text it is (eg Body, Title). You can also call
+<code>getTextRuns()</code>, which will return the
+<code>HSLFTextRun</code>s that make up the <code>TextParagraph</code>. A
+<code>HSLFTextRun</code> is a text fragment, having the same character formatting.
+The paragraph formatting is defined in the parent <code>HSLFTextParagraph</code>.
</p>
</section>
@@ -77,51 +77,49 @@ same character and paragraph formatting.
<section><title>Changing Text</title>
<p>It is possible to change the text via
- <code>TextRun.setText(String)</code> or
- <code>RichTextRun.setText(String)</code>. It is not yet possible
- to add additional TextRuns or RichTextRuns.</p>
- <p>When calling <code>TextRun.setText(String)</code>, all
+ <code>HSLFTextParagraph.setText(List<HSLFTextParagraph>,String)</code> or
+ <code>HSLFTextRun.setText(String)</code>. It is possible to add additional TextRuns
+ with <code>HSLFTextParagraph.appendText(List<HSLFTextParagraph>,String,boolean)</code>
+ or <code>HSLFTextParagraph.addTextRun(HSLFTextRun)</code></p>
+ <p>When calling <code>HSLFTextParagraph.setText(List<HSLFTextParagraph>,String)</code>, all
the text will end up with the same formatting. When calling
- <code>RichTextRun.setText(String)</code>, the text will retain
- the old formatting of that <code>RichTextRun</code>.
+ <code>HSLFTextRun.setText(String)</code>, the text will retain
+ the old formatting of that <code>HSLFTextRun</code>.
</p>
</section>
<section><title>Adding Slides</title>
<p>You may add new slides by calling
- <code>SlideShow.createSlide()</code>, which will add a new slide
- to the end of the SlideShow. It is not currently possible to
- re-order slides, nor to add new text to slides (currently only
- adding Escher objects to new slides is supported).
+ <code>HSLFSlideShow.createSlide()</code>, which will add a new slide
+ to the end of the SlideShow. It is possible to re-order slides with <code>HSLFSlideShow.reorderSlide(...)</code>.
</p>
</section>
<section><title>Guide to key classes</title>
<ul>
- <li><code>org.apache.poi.hslf.HSLFSlideShow</code>
+ <li><code>org.apache.poi.hslf.usermodel.HSLFSlideShowImpl</code>
Handles reading in and writing out files. Calls
<code>org.apache.poi.hslf.record.record</code> to build a tree
of all the records in the file, which it allows access to.
</li>
- <li><code>org.apache.poi.hslf.record.record</code>
+ <li><code>org.apache.poi.hslf.record.Record</code>
Base class of all records. Also provides the main record generation
code, which will build up a tree of records for a file.
</li>
- <li><code>org.apache.poi.hslf.usermodel.SlideShow</code>
+ <li><code>org.apache.poi.hslf.usermodel.HSLFSlideShow</code>
Builds up model entries from the records, and presents a user facing
view of the file
</li>
- <li><code>org.apache.poi.hslf.model.Slide</code>
+ <li><code>org.apache.poi.hslf.usermodel.HSLFSlide</code>
A user facing view of a Slide in a slidesow. Allows you to get at the
Text of the slide, and at any drawing objects on it.
</li>
- <li><code>org.apache.poi.hslf.model.TextRun</code>
- Holds all the Text in a given area of the Slide, and will
- contain one or more <code>RichTextRun</code>s.
- </li>
- <li><code>org.apache.poi.hslf.usermodel.RichTextRun</code>
- Holds a run of text, all having the same character and
- paragraph stylings. It is possible to modify text, and/or text stylings.
+ <li><code>org.apache.poi.hslf.usermodel.HSLFTextParagraph</code>
+ A list of <code>HSLFTextParagraph</code>s holds all the text in a given area of the Slide, and will
+ contain one or more <code>HSLFTextRun</code>s.
+ </li>
+ <li><code>org.apache.poi.hslf.usermodel.HSLFTextRun</code>
+ Holds a run of text, all having the same character stylings. It is possible to modify text, and/or text stylings.
</li>
<li><code>org.apache.poi.hslf.extractor.PowerPointExtractor</code>
Uses the model code to allow extraction of text from files
Modified: poi/site/src/documentation/content/xdocs/slideshow/xslf-cookbook.xml
URL: http://svn.apache.org/viewvc/poi/site/src/documentation/content/xdocs/slideshow/xslf-cookbook.xml?rev=1692670&r1=1692669&r2=1692670&view=diff
==============================================================================
--- poi/site/src/documentation/content/xdocs/slideshow/xslf-cookbook.xml (original)
+++ poi/site/src/documentation/content/xdocs/slideshow/xslf-cookbook.xml Sat Jul 25 23:26:37 2015
@@ -95,7 +95,7 @@
// there can be multiple masters each referencing a number of layouts
// for demonstration purposes we use the first (default) slide master
- XSLFSlideMaster defaultMaster = ppt.getSlideMasters()[0];
+ XSLFSlideMaster defaultMaster = ppt.getSlideMasters().get(0);
// title slide
XSLFSlideLayout titleLayout = defaultMaster.getLayout(SlideLayout.TITLE);
@@ -132,9 +132,9 @@
<section><title>Re-order slides</title>
<source>
XMLSlideShow ppt = new XMLSlideShow(new FileInputStream("slideshow.pptx"));
- XSLFSlide[] slides = ppt.getSlides();
+ List<XSLFSlide> slides = ppt.getSlides();
- XSLFSlide thirdSlide = slides[2];
+ XSLFSlide thirdSlide = slides.get(2);
ppt.setSlideOrder(thirdSlide, 0); // move the third slide to the beginning
</source>
</section>
@@ -158,30 +158,30 @@
The following code demonstrates how to iterate over shapes for each slide.
</p>
<source>
- XMLSlideShow ppt = new XMLSlideShow(new FileInputStream("slideshow.pptx"));
- //get slides
- XSLFSlide[] slide = ppt.getSlides();
- for (int i = 0; i < slide.length; i++){
- XSLFShape[] sh = slide[i].getShapes();
- for (int j = 0; j < sh.length; j++){
- //name of the shape
- String name = sh[j].getShapeName();
-
- //shapes's anchor which defines the position of this shape in the slide
- java.awt.geom.Rectangle2D anchor = sh[j].getAnchor();
-
- if (sh[j] instanceof XSLFConnectorShape){
- XSLFConnectorShape line = (XSLFConnectorShape)sh[j];
- //work with Line
- } else if (sh[j] instanceof XSLFTextShape){
- XSLFTextShape shape = (XSLFTextShape)sh[j];
- //work with a shape that can hold text
- } else if (sh[j] instanceof XSLFPictureShape){
- XSLFPictureShape shape = (XSLFPictureShape)sh[j];
- //work with Picture
- }
+ XMLSlideShow ppt = new XMLSlideShow(new FileInputStream("slideshow.pptx"));
+ // get slides
+ for (XSLFSlide slide : ppt.getSlides()) {
+ for (XSLFShape sh : slide.getShapes()) {
+ // name of the shape
+ String name = sh.getShapeName();
+
+ // shapes's anchor which defines the position of this shape in the slide
+ if (sh instanceof PlaceableShape) {
+ java.awt.geom.Rectangle2D anchor = ((PlaceableShape)sh).getAnchor();
+ }
+
+ if (sh instanceof XSLFConnectorShape) {
+ XSLFConnectorShape line = (XSLFConnectorShape) sh;
+ // work with Line
+ } else if (sh instanceof XSLFTextShape) {
+ XSLFTextShape shape = (XSLFTextShape) sh;
+ // work with a shape that can hold text
+ } else if (sh instanceof XSLFPictureShape) {
+ XSLFPictureShape shape = (XSLFPictureShape) sh;
+ // work with Picture
+ }
+ }
}
- }
</source>
</section>
<anchor id="AddImage"/>
@@ -221,7 +221,7 @@
XSLFTextRun r1 = p.addNewTextRun();
r1.setText("The");
r1.setFontColor(Color.blue);
- r1.setFontSize(24);
+ r1.setFontSize(24.);
XSLFTextRun r2 = p.addNewTextRun();
r2.setText(" quick");
@@ -230,7 +230,7 @@
XSLFTextRun r3 = p.addNewTextRun();
r3.setText(" brown");
- r3.setFontSize(12);
+ r3.setFontSize(12.);
r3.setItalic(true);
r3.setStrikethrough(true);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org