Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Password protected PPT files using Perl

Tags:

perl

winapi

Can someone please let me know how to use the below Microsoft Presentation Object Properties in Perl?

http://msdn.microsoft.com/en-us/library/office/bb251459(v=office.12).aspx

Basically I want to use Password property to protect the presentation.

like image 573
Shyam Avatar asked Nov 13 '22 04:11

Shyam


1 Answers

This script is based on the perlmonks article from angiehope as per the comment from @FtLie above. I have tested this with Office 2010. The script will create a file called ppt_test.ppt in the same file as the script and will set a password 'secret' on the saved document.

use strict;
use warnings;
use v5.10;

use Try::Tiny;
use Data::Dumper;
use Carp;

use FindBin qw ($Bin);

use Win32::OLE qw( in CP_UTF8 );
Win32::OLE->Option( CP => CP_UTF8 );
$Win32::OLE::Warn = 3;
my $filename = "$Bin/ppt_test.ppt";
unlink $filename if (-e $filename);

print( "Starting Powerpoint Object\n" );
my $power = Win32::OLE->GetActiveObject('Powerpoint.Application') ||
    Win32::OLE->new('Powerpoint.Application', 'Quit');

my $ppt = $power->Presentations->Add();
# 12 = blank layout
my $slide = $ppt->Slides->Add(1,12);
# 1 = text in horizontal direction, the next two numbers describe the position
# and the last numbers the width and height of the box
my $new_textbox = $slide->Shapes->AddTextbox(1,30,30,600,200);
my $text_frame = $new_textbox->TextFrame;
my $text_range = $text_frame->TextRange;
$text_range->{Text} = "Please print \x{03B1},\x{03B2},\x{03B3}";

#   Now set the password
my $password = 'secret';
$ppt->{Password} = $password;

$ppt->SaveAs($filename);
$ppt->Close();
like image 195
Ross Attrill Avatar answered Nov 15 '22 06:11

Ross Attrill