#!/usr/bin/perl use strict; use warnings; use Win32::OLE::Const 'Microsoft Word'; #$Win32::OLE::CP = CP_UTF8; binmode STDOUT, 'encoding(utf8)'; # OPEN FILE SPECIFIED AS FIRST ARGUMENT my $fname=$ARGV[0]; my $fnameFullPath = `cygpath.exe -wa $fname`; $fnameFullPath =~ s/\\/\\\\/g; $fnameFullPath =~ s/\s*$//; unless (-e $fnameFullPath) { print "Error: File did not exists\n"; exit 1;} my $Word = Win32::OLE->GetActiveObject('Word.Application') || Win32::OLE->new('Word.Application','Quit') or die Win32::OLE->LastError(); $Word->{'Visible'} = 0; my $doc = $Word->Documents->Open($fnameFullPath); my $paragraphs = $doc->Paragraphs() ; my $enumerate = new Win32::OLE::Enum($paragraphs); my $oldFont = $Word->Selection->Font; # added line while(defined(my $paragraph = $enumerate->Next())) { my $text = $paragraph->{Range}->{Text}; my $sel = $Word->Selection; my $font = $sel->Font; if (!defined($font)) { $font = $oldFont; } # use the old font instead else { $oldFont = $font; } # use this font for future paragraphs if ($font->{Size} == 18){ print "Text: ", $text, "\n"; print "Font Bold: ", $font->{Bold}, "\n"; print "Font Italic: ", $font->{Italic}, "\n"; print "Font Name: ", $font->{Name}, "\n"; print "Font Size: ", $font->{Size}, "\n"; print "=========\n"; } } $Word->ActiveDocument->Close ; $Word->Quit;