The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Win32::PowerPoint - helps to convert texts to PP slides

SYNOPSIS

    use Win32::PowerPoint;

    # invoke (or connect to) PowerPoint
    my $pp = Win32::PowerPoint->new;

    # set presentation-wide information
    $pp->new_presentation(
      background_forecolor => [255,255,255],
      background_backcolor => 'RGB(0, 0, 0)',
      pattern => 'Shingle',
    );

    # and master footer if you prefer (optional)
    $pp->set_master_footer(
      visible         => 1,
      text            => 'My Slides',
      slide_number    => 1,
      datetime        => 1,
      datetime_format => 'MMMMyy',
    );

    (load and parse your slide text)

    # do whatever you want to do for each of your slides
    foreach my $slide (@slides) {
      $pp->new_slide;

      $pp->add_text($slide->title, { size => 40, bold => 1 });
      $pp->add_text($slide->body);
      $pp->add_text($slide->link,  { link => $slide->link });

      # you may add pictures
      $pp->add_picture($file, { left => 10, top => 10 });
    }

    $pp->save_presentation('slide.ppt');

    $pp->close_presentation;

    # PowerPoint closes automatically

DESCRIPTION

Win32::PowerPoint helps you to create a PowerPoint presentation. You can add texts/pictures incrementally to your slides.

METHODS

new

Invokes (or connects to) PowerPoint.

connect_or_invoke

Explicitly connects to (or invoke) PowerPoint.

quit

Explicitly disconnects from PowerPoint, and closes it if this module invoked it.

new_presentation (options)

Creates a new (probably blank) presentation. Options are:

background_forecolor, background_backcolor

You can specify background colors of the slides with an array ref of RGB components ([255, 255, 255] for white) or formatted string ('255, 0, 0' for red). You can use '(0, 255, 255)' or 'RGB(0, 255, 255)' format for clarity. These colors are applied to all the slides you'll add, unless you specify other colors for the slides explicitly.

You can use 'masterbkgforecolor' and 'masterbkgbackcolor' as aliases.

pattern

You also can specify default background pattern for the slides. See Win32::PowerPoint::Constants (or MSDN or PowerPoint's help) for supported pattern names. You can omit 'msoPattern' part and the names are case-sensitive.

save_presentation (path)

Saves the presentation to where you specified. Accepts relative path. You might want to save it as .pps (slideshow) file to make it easy to show slides (it just starts full screen slideshow with a doubleclick).

close_presentation

Explicitly closes the presentation.

new_slide (options)

Adds a new (blank) slide to the presentation. Options are:

background_forecolor, background_backcolor

You can set colors just for the slide with these options. You can use 'bkgforecolor' and 'bkgbackcolor' as aliases.

pattern

You also can set background pattern just for the slide.

add_text (text, options)

Adds (formatted) text to the slide. Options are:

left, top, width, height

of the Textbox.

See 'decorate_range' for other options.

add_picture (file, options)

Adds file to the slide. Options are:

left, top, width, height

of the picture. width and height are optional.

If set to true, the picture will be linked, otherwise, embedded.

insert_before (text, options)

insert_after (text, options)

Prepends/Appends text to the current Textbox. See 'decorate_range' for options.

Arranges (master) footer. Options are:

visible

If set to true, the footer(s) will be shown, and vice versa.

text

Specifies the text part of the footer(s)

slide_number

If set to true, slide number(s) will be shown, and vice versa.

datetime

If set to true, the date time part of the footer(s) will be shown, and vice versa.

datetime_format

Specifies the date time format of the footer(s) if you specify one of the registered ppDateTimeFormat name (see Win32::PowerPoint::Constants or MSDN for details). If set to false, no format will be used.

decorate_range (range, options)

Decorates text of the range. Options are:

bold, italic, underline, shadow, subscript, superscript

Boolean.

size

Integer.

color

See above for the convention.

font

Font name of the text. You can use 'name' as an alias.

alignment

One of the 'left' (default), 'center', 'right', 'justify', 'distribute'.

You can use 'align' as an alias.

link

hyperlink address of the Text.

(This method is mainly for the internal use).

IF YOU WANT TO GO INTO DETAIL

This module uses Win32::OLE internally. You can fully control PowerPoint through the following accessors. See Win32::OLE and other appropriate documents like intermediate books on PowerPoint and Visual Basic for details (after all, this module is just a thin wrapper of them). If you're still using old PowerPoint (2003 and older), try Record New Macro (from the Tools menu, then, Macro, and voila) and do what you want, and see what's recorded (from the Tools menu, then Macro, and Macro... submenu. You'll see Visual Basic Editor screen).

application

returns an Application object.

    print $pp->application->Name;

presentation

returns a current Presentation object (maybe ActivePresentation but that's not assured).

    $pp->save_presentation('sample.ppt') unless $pp->presentation->Saved;

    while (my $last = $pp->presentation->Slides->Count) {
      $pp->presentation->Slides($last)->Delete;
    }

slide

returns a current Slide object.

    $pp->slide->Export(".\\slide_01.jpg",'jpg');

    $pp->slide->Shapes(1)->TextFrame->TextRange
       ->Characters(1, 5)->Font->{Bold} = $pp->c->True;

As of 0.10, you can pass an index number to get an arbitrary Slide object.

c

returns Win32::PowerPoint::Constants object.

CAVEATS FOR CYGWIN USERS

This module itself seems to work under the Cygwin environment. However, MS PowerPoint expects paths to be Windows-ish, namely without /cygdrive/. So, when you load or save a presentation, or import some materials with OLE (native) methods, you usually need to convert them by yourself. As of 0.08, Win32::PowerPoint::Utils has a convert_cygwin_path function for this. Win32::PowerPoint methods use this function internally, so you don't need to convert paths explicitly.

AUTHOR

Kenichi Ishigaki, <ishigaki@cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2006- by Kenichi Ishigaki

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.