LibPptx code examples

Detailed instructions on integrating library could be found here

A quick way to get started with LibPptx is by trying out some of the examples below to get a feel for how to use LibPptx

Hello World example

Example of title slide generated by LibPptx
PptxManager* manager = [[PptxManager alloc] initWithPptx:SRC];
Presentation* presentation = [manager presentation];
       
Slide* slide1 = [presentation addSlideWithLayoutId:2];
        
Title* title = [[slide1 createShapeOfType:[Title class]] withText:@"Hello world!"];
[[[[title getContent] withBold:YES] withItalic:YES] withSizePt:72];
        
[slide1 addShape: title];
[slide1 addShape: [[slide1 createShapeOfType:[SubTitle class]] withText:@"LibPptx generated this"]];

[manager save];

Bullet slide example

Example of bullet slide generated by LibPptx
PptxManager* manager = [[PptxManager alloc] initWithPptx:SRC];
Presentation* presentation = [manager presentation];

Slide* slide2 = [presentation addSlideWithLayoutId:4];

[slide2 addShape:[[slide2 createShapeOfType:[SlideTitle class]] withText:@"Bullet slide"]];
        
List* list = [slide2 createShapeOfType:[List class]];
[list addItem:[[[[ListItem new] withText:@"Top level"] withLevel:1] withBold:YES]];
[list addItem:[[[[ListItem new] withText:@"Item on 2nd level with italic text"] withLevel:2] withItalic:YES]];
[list addItem:[[[[ListItem new] withText:@"3rd level with text size of 20pt"] withLevel:3] withSizePt:20]];
[list addItem:[[[[ListItem new] withText:@"4th level with underlined text"] withLevel:1] withUnderline:UNDERLINE_DBL]];
[slide2 addShape:list];       

[manager save];

Textbox example

Example of slide with textboxes generated by LibPptx
PptxManager* manager = [[PptxManager alloc] initWithPptx:SRC];
Presentation* presentation = [manager presentation];

Slide* slide3 = [presentation addSlideWithLayoutId:0];
[slide3 addShape:[[slide3 createShapeOfType:[SlideTitle class]] withText:@"Textbox example"]];
        
TextBox* textBox = [slide3 createShapeOfType:[TextBox class]];
        
[[[[textBox
    withWidth:[Inch of:8]] withHeight:[Inch of:2]]
    withLeft:[Inch of:2]] withTop:[Inch of:6]];
        
[textBox addItem:[[[[Paragraph new] withText:@"This is a first paragraph"] withSizePt:20] withAlign:ALIGN_LEFT]];
[textBox addItem:[[[[Paragraph new] withText:@"This is a second paragraph"] withSizePt:30] withAlign:ALIGN_LEFT]];
[slide3 addShape:textBox];
       
[manager save];

Picture example

Example of slide with multiple images generated by LibPptx
PptxManager* manager = [[PptxManager alloc] initWithPptx:SRC];
Presentation* presentation = [manager presentation];

Slide* slide4 = [presentation addSlideWithLayoutId:0];
[slide4 addShape:[[slide4 createShapeOfType:[SlideTitle class]] withText:@"Picture example"]];
        
Image* image1 = [[slide4 createShapeOfType:[Image class]]
                 withImageUrl:[NSURL URLWithString:@"/work/ppt1.jpg"]];
[[[[image1 withTop:[Inch of: 1]] withLeft:[Inch of:1]] withWidth:[Inch of:1]] withHeight:[Inch of:1]];
        
Image* image2 = [[slide4 createShapeOfType:[Image class]]
                 withImageUrl:[NSURL URLWithString:@"/work/ppt2.jpg"]];
[[[[image2 withTop:[Inch of: 3]] withLeft:[Inch of:1]] withWidth:[Inch of:5]] withHeight:[Inch of:3]];
        
[slide4 addShape:image1];
[slide4 addShape:image2];
       
[manager save];

Autoshape example

Example of slide with autoshapes generated by LibPptx
PptxManager* manager = [[PptxManager alloc] initWithPptx:SRC];
Presentation* presentation = [manager presentation];

Slide* slide5 = [presentation addSlideWithLayoutId:4];
        
[slide5 addShape:[[slide5 createShapeOfType:[SlideTitle class]] withText:@"Autoshapes"]];
        
AutoShape* as1 = [[slide5 createShapeOfType:[AutoShape class]] withType:@"AS_PENTAGON"];
[[[[as1 withLeft:[Inch of:1]] withTop:[Inch of:3]] withWidth:[Inch of:1]] withHeight:[Inch of:1]];
[[[as1 withText:@"Step 1"] getContent] withSizePt:15];
[[[as1 getShapeStyle] fill] withSchemeClr:@"accent6"];
[slide5 addShape:as1];
        
float d = 0.4, x = 1.6;
for (int i = 0 ; i < 4 ; i++)
{
    AutoShape* as = [[slide5 createShapeOfType:[AutoShape class]] withType:@"AS_CHEVRON"];
    [[[[as withLeft:[Inch of:(x + i*(2.0-d))]] withTop:[Inch of:3]] withWidth:[Inch of:2]] withHeight:[Inch of:1]];
    [[[as withText:[NSString stringWithFormat:@"Step %d", i+1]] getContent] withSizePt:15];
    [[[as getShapeStyle] fill] withSchemeClr:[NSString stringWithFormat:@"accent%d", (5-i)]];

    [slide5 addShape:as];
}
       
[manager save];

Table example

Example of slide with table generated by LibPptx
PptxManager* manager = [[PptxManager alloc] initWithPptx:SRC];
Presentation* presentation = [manager presentation];

Slide* s6 = [presentation addSlideWithLayoutId:0];
[s6 addShape:[[s6 createShapeOfType:[SlideTitle class]] withText:@"Slide title 6"]];

Table* table = [s6 createShapeOfType:[Table class]];

[[table withFirstRow:YES] withBandedRows:YES];
[table withColumns:@[[Inch of:1], [Inch of:2], [Inch of:3]]];

[[[[table withLeft:[Inch of:1]] withTop:[Inch of:2]] withWidth:[Inch of:5]] withHeight:[Inch of:5]];

TableRow* tr1 = [[table addRow] withHeight:[Centimeter of:1]];
[tr1 addCell:[[TableCell alloc] initWithText:@"Header 1"]];
[tr1 addCell:[[[TableCell alloc] initWithText:@"Header 2"] withColSpan:2]];

TableRow* tr2 = [[table addRow] withHeight:[Centimeter of:1]];
[tr2 addCell:[[TableCell alloc] initWithText:@"Lorem ipsum"]];
[tr2 addCell:[[TableCell alloc] initWithText:@"dolor sit amet"]];
[tr2 addCell:[[TableCell alloc] initWithText:@"consectetur"]];

TableRow* tr3 = [[table addRow] withHeight:[Centimeter of:1]];
[tr3 addCell:[[TableCell alloc] initWithText:@"adipiscing elit"]];
[tr3 addCell:[[TableCell alloc] initWithText:@"sed do eiusmod tempor"]];
[tr3 addCell:[[TableCell alloc] initWithText:@"incididunt ut labore et dolore magna aliqua"]];

[s6 addShape:table];

[manager save];

Chart example

Example of slide with chart generated by LibPptx
Slide* s7 = [presentation addSlideWithLayoutId:0];
        
[s7 addShape:[[s7 createShapeOfType:[SlideTitle class]] withText:@"Chart example"]];
BarChart* chart = [s7 createShapeOfType:[BarChart class]];
        
ChartData* chartData = [[[[ChartData alloc] initWithCategories:@[@"East", @"West", @"Midwest"]]
                       addSeriesWithName:@"Series 1" andValues:@[@10.5, @20.2, @30.3]]
                       addSeriesWithName:@"Series 2" andValues:@[@5, @7, @10]];
        
[chart withChartData:chartData];
[[[[chart withTop:[Inch of:2.2]] withLeft:[Inch of:2.5]] withWidth:[Inch of:5]] withHeight:[Inch of:3]];
        
[s7 addShape:chart];

Slide notes

Example of slide notes generated by LibPptx
[[slide1 notesSlide] addShape:[[[SlideNoteText alloc] init] withText:@"lorem\nipsum\ndoloret"]];