Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Editing Binary PowerPoint files

by punchcard_don (Beadle)
on Mar 18, 2004 at 19:06 UTC ( #337768=perlquestion: print w/replies, xml ) Need Help??

punchcard_don has asked for the wisdom of the Perl Monks concerning the following question:

Miraculous Monks,

A great deal of hunting around for a solution to my dynamically-generated PowerPoint file project has lead to frustration.

Yes, technically, it can be done throug Automation of MS Office, BUT in this case it has to be done on a remote server, and few ISP's want to install MS Office, or they charge an arm and a leg for it. Then there's MS' own dire warnings about Office components not being intended for servers and therfore being unstable.

Yes, technically, it can be done using OpenOffice's PPT-clone which has both XML-support and a PPT export filter. BUT, OO can only be installed/run with X-server (or at least vncxserver, etc.) also installed, and, same thing - noone wants to do that to their production servers.

Besides, both solutions would be bloated by the install of these huge programs, and probably terribly slow, what with start-up latency and all.

All I want to do is change a dozen numbers in a chart in a PPT slide presentation file. The file already exists as a template.

Soooooooooooooooo - I'm down to the unenviable solution of directly editing the binary ppt file. My question to my fellow Monks is - can it be done in Perl? (and if so, how would be appreciated)

Thanks.

janitored by ybiC: Shortened display of loooong URL for benefit of monks using smallish browser windows.

Replies are listed 'Best First'.
Re: Editing Binary PowerPoint files
by waswas-fng (Curate) on Mar 18, 2004 at 19:35 UTC
    As for the Xserver requirement try out Xvfb it allows you to run a virtualized (fake) Xserver to eat the windows created by java or other X apps that really don't need interaction. The link above has instructions on how to set it up. As for editing the powerpoint file directly the specs are not well documented and MS tends to toss in weird behaviors in their file formats to make it hard to directly edit them -- so I would avoid doing so if you can.


    -Waswas
Re: Editing Binary PowerPoint files
by dragonchild (Archbishop) on Mar 18, 2004 at 19:43 UTC
    All of MS Office supports some version of XML. (At least, Word and Excel both do.) This isn't to say that the XML spec is documented, but you might be able to reverse-engineer it by saving your powerpoint projects as XML and seeing what happens ... (Of course, if you do this, I'd highly recommend putting at least the spec on the Net so that others can benefit from it, if not making a CPAN distribution .......)

    ------
    We are the carpenters and bricklayers of the Information Age.

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

      All of MS Office supports some version of XML.

      I do so wish that were true. And MS did promise it in Office 2003. Alas, they remain true to form: PowerPoint is the only Office 2003 component with no, zero, XML support. I would be elated to be proven wrong!!!

Re: Editing Binary PowerPoint files
by iburrell (Chaplain) on Mar 18, 2004 at 21:50 UTC
    For a previous job, I wrote a text extractor for PowerPoint files. From what I remember about the format, even your text changer would not be an easy job. The file is basically a bunch of serialized objects stored in an OLE stream. The text extracter walked through the object tree and recognized the text objects.

    It might be possible to modify the strings in place because they are simplest objects. But it would be a pain to insert the changes in the file. I forgot if there are offsets and sizes that would need to be adjusted but I suspect there are.

    I would worry about the reliability of the binary editor. I bet it would be brittle to changes.

      Granted, but in absence of a better solution, I've got to give it a try. I figure my one hope is the simplicity of the changes. A chart with four values - switch old values for new - and three words in a line of text. Doing the text replacement manually in HexEdit appears to work just fine. Can it be that fragile?
Re: Editing Binary PowerPoint files
by Zero_Flop (Pilgrim) on Mar 19, 2004 at 06:47 UTC
    Is there a reason that this has to be in PowerPoint? Do you have to server the PPT file from the server?

    There may be other ways of doing what you want could you can go more into the requiements. (ex generate a PDF file from HTML or have the PPT slide pull the data from the server when it is opened or when an update button is pressed.)
      "the PPT slide pull the data from the server when it is opened"

      Now that is a possibility. Client insists it be a ppt file, and that it be served from the server (it must not be necessary that the user already have the file), but, whether the data is inserted on the server, or atumoatically from the server once downloaded and opened is immaterial.

      I'm not an MS Office buff. I'm somewhat familiar with linking objects in other Office apps, but from the server? On top of that, it has to be linked to a Perl script because teg data is being generated on the fly.

        Here you go.

        If you go here  PowerPoint Slide you will have a slide that has directions on how to update the data from  this web page.

        So in this  example you write a Perl script that generates your data on a web page dynamicly. Then have a file simular to this
        one pull the data and update your file.

        I did not go into too much details on how to do this. Bad day and all, but if you think that you would want to try this I
        can give you some tips.

        Updated links which changed due to changes on my website.
Re: Editing Binary PowerPoint files
by punchcard_don (Beadle) on Mar 18, 2004 at 21:23 UTC
    Xvfb - yes, normally a good idea, but it was included in the "etc."

    Since posting, I've played with a PPT file in HexEdit and been able to do a simple replacement of a piece of text in a slide successfully. No errors uopn re-opening the file in PPT. Next two steps is

    1) Write a Perl script that makes the same change as I did manually in HexEdit

    2) Install the PPT Charting utility (gotta find my Office CD, I know it's aroud here somewhere...) os I can re-try these steps with a chart.

    Thanks for "binmode". I did some reading and am not clear on editing files in binmode. I expect I'll be using simple regex's =~ s/$placeholder/$new_value, but will placeholder be the ascii string I'm lookig for (ex: **punchard_dons_placeholder**), or the hex code, or the binary code of that string?

    If I can get this working, I'll post the salient features for reference.

Re: Editing Binary PowerPoint files
by Anonymous Monk on Mar 18, 2004 at 20:23 UTC
    My question to my fellow Monks is - can it be done in Perl? (and if so, how would be appreciated)
    Sure why not (it's perl). Here's how
    open FILE, 'foo.ppt' or die "$!"; binmode FILE; read FILE, my $file, -s FILE, 0; close FILE;
      Er, you seem to have missed the "editing" part...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://337768]
Approved by matija
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2022-06-28 12:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My most frequent journeys are powered by:









    Results (91 votes). Check out past polls.

    Notices?