Late with this answer. Maybe someone else can profit..
you do not need imagemagick.M
see : http://support.microsoft.com/kb/555171
use strict;
# import OLE
use Win32::OLE qw(in with);
use Win32::OLE::Const;
use Win32::OLE::Const 'Microsoft Word';
$Win32::OLE::Warn = 3; # report OLE runtime errors
sub Win32_FullPath;
if ( $#ARGV == -1 ) {
print "Specify a msword file as first commandline argument. Full p
+ath to the file is needed\n";
exit;
}
# specify variables
my $filename = $ARGV[0];
chomp $filename;
$filename = Win32_FullPath( $filename ) ;
my ( $basename ) = $filename;
$basename =~ s/\.doc$/_files/;
if ( ! -f $filename ) {
print "Could not find file : $filename\n";
exit;
}
# instantiate Word - use the Word application if it's open, otherwise
+open new
print "Starting word\n";
my $Word = "";
$Word = Win32::OLE->GetActiveObject('Word.Application')
|| Win32::OLE->new('Word.Application', sub {$_[0]->Quit;} ) || di
+e "MsWord is not installed\n"; # get already active msword
#print ref $Word ,"\n";
if ( ref $Word ne 'Win32::OLE' ) {
print "Cound not open word\n";
exit;
}
$Word->{Visible}= 0; # we don't need to see Word in an active window
# open the specified Word doc
print "Opening $filename\n";
$Word->Documents->Open( $filename )
or die("Unable to open document ", Win32::OLE->LastError());
my $savenameHTML = "";
( $savenameHTML = $filename) =~ s/\.doc$/\.html/;
$Word->ActiveDocument->SaveAs({
FileName => $savenameHTML,
FileFormat => wdFormatHTML});
# close document
print "Closing document and Word\n";
$Word->ActiveDocument->Close();
print "Pictures are in directory : \"$basename\"\n";
exit;
sub Win32_FullPath ($) {
# This sub will return the appropiate WINDOWS file name ( e.g. / will
+be \
# c:/hoge/hoge.xls -> c:\hoge\hoge.xls
my $file = shift;
if ($] ge 5.006) {
$file = Win32::GetFullPathName($file);
}
$file =~ s|/|\\|g;
print "SUB win32::FullPath : $file\n";
return "$file";
}
Notice : See also : http://cnedelcu.blogspot.nl/2013/02/top-3-ways-to-extract-images-from-word-docx-doc-document.html |