Dear monks

before I reinvent the wheel I want to ask if you know a robust module or procedure to convert PowerPoint to Text in pure Perl (i.e. no OLE, etc.). In Python and co there are some quite robust modules for this. For the moment I came out with the following, which gives me the text file, divided in Slides with basic formatting (just putting together sentences). However, there is a lot of possible formatting in PowerPoint, I guess, and before I start studying their documentations and try to come out with something more general than my script (it doesn't take into considerations Lists, for example, and who knows how many other things), I want to ask for your opinion.

use strict; use warnings; use utf8; use Archive::Zip qw( :ERROR_CODES ); use XML::Twig; use Data::Dumper; my $PathDocument="myDocument.pptx"; our @textPPT; my $zip = Archive::Zip->new(); $zip->read( $PathDocument ) == AZ_OK or die "Unable to open Office + file\n"; my @slides = $zip->membersMatching( "ppt/slides/slide.+\.xml" ); for my $i ( 1 .. scalar @slides ) { push @textPPT, "\n\nSLIDE $i\n\n"; my $content = $zip->contents( "ppt/slides/slide${i}.xml"); my $twig= XML::Twig->new( #keep_encoding=>1, twig_handlers => { 'a:t' => \&text_processing, 'a:endParaRPr' => \&line_processing, 'w:tab' => \&tab_processing, }, ); $twig->parse( $content ); } my $text=join("", @textPPT); #BASIC FORMATTING $text =~ s/ +/ /g; print $text; sub text_processing { my($twig, $ppttext) = @_; push @textPPT, $ppttext->text(); } sub line_processing { my($twig, $ppttext) = @_; push @textPPT, "\n"; } sub tab_processing { my($twig, $ppttext) = @_; push @textPPT, "\t"; }

In reply to PPT to TXT Pure Perl by Takamoto

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.