PowerPoint
documents using the DBStudio
JavaScript
libraries.
1 PowerPoint
A new PowerPoint
object can be easily creatad with:
var ppt = new Ax.ms.PowerPoint();
Alternatively, we can load a PowerPoint
from a source object:
var ppt = new Ax.ms.PowerPoint(); ppt.load("https://bitbucket.org/deister/axional-docs-resources/raw/master/PPT/TestPPTDashboard.pptx");
2 Slides
To create an slide, a slide layout is first needed. A slide layout defines the structure of the slide. Slide layouts can be obtained from the slide master. Default master is 0.
Let's look at the following example:
var ppt = new Ax.ms.PowerPoint(); // Get 1st layput var layout1 = ppt.getSlideMaster(0).getLayout(Ax.ms.PowerPoint.SlideLayout.TITLE_ONLY); // Get 2nd layout var layout2 = ppt.getSlideMaster(0).getLayout(Ax.ms.PowerPoint.SlideLayout.TITLE_AND_CONTENT);
As we can see, the first layout is obtained by getting it from the default slide master (0). The first layout only contains a title paragraph. Similarly, we obtain the layout through the slide master. In this case the layout contains a title and a content region. These are all the possible layouts:
Title layout with centered title and subtitle placeholders: | |||
---|---|---|---|
TITLE | |||
Title and text: | |||
TEXT | TWO_COL_TX | TBL | TEXT_AND_CHART |
Title, chart on left and text on right: | |||
CHART_AND_TEXT | DGM | ||
Title and chart: | |||
CHART | TX_AND_CLIP_ART | ||
Title, clipart on left, text on right: | |||
CLIP_ART_AND_TEXT | |||
Title only: | |||
TITLE_ONLY | |||
Blank: | |||
BLANK | TX_AND_OBJ | OBJ_AND_TX | OBJ_ONLY |
Title and content: | |||
TITLE_AND_CONTENT | TX_AND_MEDIA | MEDIA_AND_TX | OBJ_OVER_TX |
TX_OVER_OBJ | TX_AND_TWO_OBJ | TWO_OBJ_AND_TX | TWO_OBJ_OVER_TX |
FOUR_OBJ | VERT_TX | CLIP_ART_AND_VERT_TX | VERT_TITLE_AND_TX |
VERT_TITLE_AND_TX_OVER_CHART | TWO_OBJ | OBJ_AND_TWO_OBJ | TWO_OBJ_AND_OBJ |
CUST | |||
Section Header: | |||
SECTION_HEADER | TWO_TX_TWO_OBJ | OBJ_TX | PIC_TX |
Now, with the obtained layout we can create a new PowerPoint
slide:
var ppt = new Ax.ms.PowerPoint(); // Get 1st layout var layout1 = ppt.getSlideMaster(0).getLayout(Ax.ms.PowerPoint.SlideLayout.TITLE_ONLY); // Get 2nd layout var layout2 = ppt.getSlideMaster(0).getLayout(Ax.ms.PowerPoint.SlideLayout.TITLE_AND_CONTENT); //Create title slide var slide1 = ppt.createSlide(layout1); //Create 5 body slides for (int i = 0; i < 5; ++i) { var slide2 = ppt.createSlide(layout2); }
2.1 Slide contents configuration
To better understand the configuration possibilities of slides' contents, let's look at the following example where paragraph objects and text runs are used:
var ppt = new Ax.ms.PowerPoint(); // Get 1st layout var layout1 = ppt.getSlideMaster(0).getLayout(Ax.ms.PowerPoint.SlideLayout.TITLE_ONLY); // Get second layout var layout2 = ppt.getSlideMaster(0).getLayout(Ax.ms.PowerPoint.SlideLayout.TITLE_AND_CONTENT); // Create 1st slide (title) var slide1 = ppt.createSlide(layout1); slide1.setTitle("Sample PowerPoint"); slide1.addPicture( "http://icons.iconarchive.com/icons/ziggy19/microsoft-office-mac-tilt/128/PowerPoint-icon.png", 320, 230, 100, 92 ); // Create 5 slides with its own title and content with bullet points for (var s = 0; s < 5; s++) { var slide2 = ppt.createSlide(layout2); slide2.setTitle("Presentation part " + (s+1)); slide2.clearText(); // Creates 5 paragraphs with bullet points at 5 indentation levels for (var p = 0; p < 5;p++) { var para = slide2.addParagraph() para.setIndentLevel(p); para.setBullet(true); para.setBulletFontColor(0, 0, 255); var text = "Slide + " + (s+1) + " Paragraph " + (p+1); // First paragraph has special configuration, next ones not if (p > 0) { para.setText(text); } else { var r0 = para.addNewTextRun(); r0.setText(text); r0.setFontSize(30); r0.setBold(true); r0.setItalic(true); r0.setFontColor(90, 10, 0); } } } return ppt.toBlob();
The resulting PowerPoint
has the following aspect: